Why New Domain Keeps Forwarding to Old Domain [Solution]

After changing a domain name and updating the DNS records you might find yourself baffled by the fact that the site continues to redirect to the old domain. You may be frustrated as you have seemingly tried everything.

Likely, you are dealing with a WordPress site. With a WordPress website, references to the domain name are hard coded into the database.

Migrating WordPress site to new Domain Name

After changing a domain name for a WordPress site, the database will need to be updated to reflect the change. Failing to change the references to the old domain name in the database means the site is still attempting to point at the old domain name.

To fix this issue, perform the MySQL queries shown below. In case it is not obvious, replace ‘old-site’ with the name of your previous domain name, and replace ‘new-site’ with your current domain name.

CAUTION: Remember to first make a backup of your current database.

MySql queries for migrating site to new domain

The MySql queries for migrating site to new domain are as follows:

SELECT option_value FROM wp_options
WHERE  option_name = 
        'home' OR option_name = 'siteurl';

UPDATE wp_options 
SET    option_value = replace(
         option_value, 'http://www.old-site.com/', 'http://www.new-site.com/'

UPDATE wp_posts 
SET    guid = replace(guid, 
         'http://www.old-site.com/', 'http://www.new-site.com/'

UPDATE wp_posts 
SET    post_content = replace(
         post_content, 'http://www.old-site.com/', 'http://www.new-site.com/'

Leave a Reply

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