Easier way to change WordPress URL
27 Jan 2009
WordPress stores the site URL in the database rather than in a file like config.php (which I have never understood), and it's a pain to have to type out the UPDATE SQL or search in phpMyAdmin/Query Browser/NaviCat to change it.
But I just found out there's a quicker way:
1. Write this at the top of wp-config.php:
define('RELOCATE',true);2. Visit wp-login.php, and WordPress will update the URL for you.
3. Log in, go to Settings and change the "Blog address" to match the new "WordPress address".
Remember to remove the line from wp-config.php afterwards.
Update (21 Mar 2010)
Fayaz suggested a better way, which puts the URL permanently into the config file (where I think it belongs) instead of the database:
define('WP_HOME', 'http://domain.com/path/to/wordpress');
define('WP_SITEURL', 'http://domain.com/path/to/wordpress');Update (13 Jun 2010)
Jonathan added that you may want to update Permalinks and content as well:
UPDATE wp_posts
SET guid
= REPLACE(guid, 'http://www.old.com', 'http://www.new.com');
UPDATE wp_posts
SET post_content
= REPLACE(post_content, 'http://www.old.com', 'http://www.new.com');I also change the trackbacks, when I've linked to my own posts:
UPDATE wp_comments
SET comment_author_url
= REPLACE(comment_author_url, "http://www.old.com", "http://www.new.com")
WHERE comment_type <> "";This blog post is archived. Comments are no longer available.