Changing the Domain of a WordPress Site

You've got a WordPress site, and you've had to change the domain name where it's hosted. Suddenly none of the links on the site work. How do you fix it?

Well, you've got some manual database updates ahead of you. WordPress comes with a MySQL database. You'll need to log in and run a few SQL statements to make the necessary changes.

Don't worry if you don't know the login information for your WordPress site's database. That information can be found in one of the WordPress source files, which can be found at:

      <wordpress-dir>/wp-config.php

Armed with this information, you can login and (carefully) make the necessary changes. You should seriously consider backing up the database before you make any changes. See my earlier article on doing MySQL database dumps.

OK. First, we'll need to change two settings in the WP_OPTIONS table, "siteurl" and "home":

UPDATE wp_options
   SET option_value = 'http://yourdomain.com'
 WHERE option_name = 'siteurl';

UPDATE wp_options
   SET option_value = 'http://yourdomain.com'
 WHERE option_name = 'home';

Next, there is the WP_POSTS table. The "guid" column of this table lists the full URL of a revision of a post. There can be a lot of rows in this table, and every row needs to have the domain name portion of its "guid" updated.

It's tedious, but doable.

By updating these two settings in the WP_OPTIONS table and the URL's in the WP_POSTS table, you can successfully move your WordPress site to a different domain name.



Comments

No comments yet. Be the first.



Leave a Comment

Comments are moderated and will not appear on the site until reviewed.

(not displayed)