Topics

On this page

Last updated on Dec 18, 2020

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');

Comments

  1. Nice outline of what needs to be changed. I guess you would have to do this if you had no choice, but I prefer to use wp-cli search-replace…. A lot less typing and it’s done with one command. There is even a –dry-run option.