The purpose of this article is to explain how to easily change the primary domain name of your WordPress site using phpMyAdmin.
Procedure
In our examples, please note that we use:
- https://www.old-site.com as our current/old website; and
- https://www.new-site.com as the new one we want to change
First Step: Files and Database(s) Backup
We strongly recommend that you perform a full backup of your files and databases to avoid any data loss during the process.
Once the backup is complete, you can move your site (files and databases) from one server to another or proceed with the URL change.
Second Step: Replace Old Website Reference
It is important to know that WordPress sites are mainly configured in the database, which means that any URL changes must be made in the database.
To notify WordPress of the URL change, we use SQL with the MySQL replace() function.
The first command to enter in MySQL is:
UPDATE wp_options SET option_value = replace(option_value, 'https://www.old-site.com', 'https://www.new-site.com') WHERE option_name = 'home' OR option_name = 'siteurl';
This command aims to replace the old URLs with the new URL in the wp_options table.
Third Step: Replace Relative URL From Posts
This step involves replacing all URLs associated with different posts in the wp_posts table.
The command to enter in MySQL is:
UPDATE wp_posts SET guid = replace(guid, 'https://www.old-site.com','https://www.new-site.com');
Fourth Step: Replace URL From Posts Contents
To ensure that all references to your old URL in posts are replaced, you must perform a search and replace on all posts on the site using this command:
UPDATE wp_posts SET post_content = replace(post_content, 'https://www.old-site.com','https://www.new-site.com');
Once this step is complete, you can immediately use the new URL to login to your admin interface. If you are still unable to do so, we recommend clearing your cache and everything should work perfectly.