Need to change the name of the primary domain of your WordPress site without having to start from scratch? This tutorial is for you, We will guide you step by step to allow you to perform this operation successfully.
-
Backing up files and databases
To prevent data loss in the process we strongly recommend that you perform a full backup of your files and databases to avoid any loss in the process. Once the backup is done you can move your site (files + Database) from one server to another or proceed to the url change.
-
Replace the references to the old website
It is important to know that setting up a WordPress website is mainly in the database, which implies that any changes to the url must be made in the database.
To indicate the changed url to WordPress we'll use SQL with the function replace () mysql.
The first command to enter MYSQL is:UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-site.com', 'http://www.new-site.com') WHERE option_name = 'home' OR option_name = 'siteurl';
This command will do the replacement of old URL by the new URL in the table wp_options
-
Replacing the relative URL of posts
This step is to replace in the table wp_posts all associated urls for the various posts
UPDATE wp_posts SET guid = replace(guid, 'http://www.old-site.com','http://www.new-site.com');
old-site.com corresponding to the URL of your old domain name and new-site.com corresponding to the URL of your new domain name.
-
Replace the URL in the content of posts
To ensure that all references to your old url in posts are replaced we will conduct a search / replace on all posts on the site
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-site.com', 'http://www.new-site.com');
old-site.com corresponding to the URL of your old domain name and new-site.com corresponding to the URL of your new domain name.
This step closes the process. You can now use the new URL to log into your administration interface, in case you are still unable sure to clear your cache and everything should work perfectly.