How to change domain of Wordpress sites

Our company uses many sites hosted by WordPress. But in some cases, we still have to assign some different URLs for them. So, we will explain the details of changing below.


Change DNS records to point the new domain to your server


Step 1: Back up everything you have: Nginx / Apache config, database
Step 2: If your domain has SSL by Let’s Encrypt and self-supported. So please follow some extra steps

Nginx: sudo certbot --nginx -m <your new domain\>
Apache: sudo certbot --apache -m <your new domain\>
Edit your sites-enabled config to update your old domain to new domain
Restart your Nginx / Apache server

Step 3: Edit file wp_config.php and add 2 extra lines:

define( 'WP_HOME', '' );
define( 'WP_SITEURL', '' );

Step 4: Access to your database
Notice: old_domain and new_domain don’t have http / https in prefix

UPDATE wp_posts SET guid = replace(guid, 'old_domain','new_domain');
UPDATE wp_posts SET post_content = replace(post_content, 'old_domain', 'new_domain');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'old_domain','new_domain');

Enjoy your success!


Hope that there is a chance for me to do it by myself :smiley:

1 Like

Anw, I don’t understand how to use your guide, but I’m really appreciate the action Documenting your know-how right away :smiley:

1 Like