Some Light Reading

How To Change All Your Links When You Move Your WordPress Website To A New Domain

This post was written by Gregory Preen and published on 8th May 2018 under the categories: Wordpress

Sometimes there comes a need for a business to move their website from one domain to another. It maybe due to branding requirements, a name change or that you created the website in a test environment and now need to move it to the live domain.

Within the WordPress admin panel you can go to the settings tab and change both the WordPress Address and the Site Address which is great. However, if you have included various internal links within the content of your website pages or blog posts then these will not be updated. For example if you have a blog post and within that post you link to another page on your website then this link will always be directed to the old url. You can always include 301 redirects so it automatically gets redirected, and if you are moving your existing site due to a name change then this should always be implemented regardless, but if have simply created a website in a test environment and want to put it live, 301 redirects as the solution will not only take time, but will appear unprofessional to anyone who may be copying the link or posting the link on social media.

The Solution

There is a solution to this issue that takes very little time to implement and gives you the result you want. it involves accessing your database and running some code. Whenever making changes to your database you should always ensure you take a backup as mistakes can easily be made especially if you are not experienced in how the database is setup and works.

Once you have taken a backup, you should access your database through PHP MyAdmin and click on the SQL tab. From there you will need to enter the following code, replacing the appropriate part with your old url and your new url:

UPDATE wp_posts SET guid = replace(guid, ‘http://www.oldurl’,’http://www.newurl’);

UPDATE wp_posts SET post_content = replace(post_content, ‘http://www.oldurl’, ‘http://www.newurl’);

UPDATE wp_postmeta SET meta_value = replace(meta_value,’http://www.oldurl’,’http://www.newurl’);

Change WordPress Site URLS

Once you have amended and added this code click “go” and it will replace all references in your web pages to your old url with your new url. Job done!

 

Add Your Comment

Your email address will not be published. Required fields are marked *