Change WordPress Domain Name

If you ever decided to change your WordPress site’s domain, firing up following MySQL queries can reduce internal redirections.

Assumptions:

  1. old.com is old-domain
  2. new.com is new-domain

Queries:

UPDATE `wp_options` SET option_value = replace(option_value, 'http://www.old.com', 'http://www.new.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE `wp_posts` SET post_content = replace(post_content,'http://old.com','http://new.com');
UPDATE `wp_postmeta` SET meta_value = replace(meta_value,'http://old.com','http://new.com');
UPDATE `wp_comments` SET comment_author_url = replace(comment_author_url,'http://old.com','http://new.com');
UPDATE `wp_comments` SET comment_content = replace(comment_content,'http://old.com','http://new.com');
UPDATE `wp_commentmeta` SET meta_value = replace(meta_value,'http://old.com','http://new.com');

Above will take care of, options table, posts & comments. If you have any other database table/column which need change you can run queries like below any number of times:

UPDATE `TABLE_NAME` SET meta_value = replace(COLUMN_NAME,'http://old.com','http://new.com');

Leave a Reply