---
url: /cookbook/migrate-domains.md
description: >-
  Migrate WPCE content between domains by updating URLs embedded in
  base64-encoded document metadata with SQL.
---

# Migrate to Another Domain

If you want to deploy your site e.g. from `dev.mysite.com` to `mysite.com`, you'll have to
perform the following steps to make it work easily:

1. Move your site as usual.
2. Run the prepared SQL query as shown below to migrate the WPCE contents.

:::tip
Use this tool to build the SQL queries: [tools.ownb.it/deployment](https://tools.ownb.it/deployment/)
:::

## Replace URLs in WPCE Content

Have a look at this query:

```sql
UPDATE wp_postmeta
  SET meta_value = TO_BASE64(replace(FROM_BASE64(meta_value),
    'https://dev.mysite.com',
    'https://mysite.com'))
  WHERE meta_key = '_wpce_doc';
```

## Replace URLs in General

You might need these queries right now as well:

```sql
UPDATE wp_postmeta
  SET meta_value = replace(meta_value,'https://dev.mysite.com','https://mysite.com');

UPDATE wp_options
  SET option_value = replace(option_value,'https://dev.mysite.com','https://mysite.com');

UPDATE wp_posts
    SET post_content = replace(post_content,'https://dev.mysite.com','https://mysite.com');
```

However, since there are tools (like [ACF](https://www.advancedcustomfields.com/)) that store some information in [PHP-serialized strings](https://www.php.net/manual/en/function.serialize.php), it often is preferable to use a dedicated tool for the job.

[Better Search Replace](https://wordpress.org/plugins/better-search-replace/) is such a tool; it's a plugin which replaces strings in the WordPress database. Use it to replace `https://dev.mysite.com` with `https://mysite.com` and, with a high degree of certainty, you'll be fine.
