Moving wordpress install across domains

As wordpress hardcodes urls to posts in the database, it can be very annoying when you alternate between a production and a dev server. Luckily, it is possible to overwrite this global url by specifying two lines in wp-config:

define('WP_SITEURL', 'http://www.mynewsiteaddress.com/');
define('WP_HOME', 'http://www.newsiteaddress.com/');

Please note that some plugins that use the file system like ssome caches may have to be reconfigured or the cache may be reconfigured. Rather than hardcoding the domain name, you can even use $_SERVER[‘HTTP_HOST’];

Alternatively, you can replace the values in the database with the search and replace plugin http://wordpress.org/extend/plugins/search-and-replace/ .

Note, some images in the database such as 2011 theme header images or absolute link will not be affected by this trick. To avoid problems, I suggest using relative urls (most importantly, avoiding putting in the domain name).

Leave a Reply

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