Themergency fooplugins.com

Migrating Your WordPress Site To A New URL

| 8 Comments

There have been many posts on this subject and there are lots of plugins to help you do this. I personally use Backup Buddy to migrate sites, especially if I want to migrate a site in or out of a multisite install (check out my previous walk through on how to do this).

But sometimes you do not want to go through the hassle of installing plugins. Maybe you just want to login to your web server, zip up your WordPress folder, script your entire DB and do it all manually. If you know how, this can be a really simple process.

Or perhaps you just want to change the URL of your site - you want to keep it hosted on the same server, but you just want to change the url, for example, from http://www.mysite.com to http://mysite.com/wp/ .

These are the SQL commands I run to make this change:
/* update all post permalinks */
update wp_posts
set guid = REPLACE(guid, 'http://oldurl.com', 'http://www.newurl.net')
where guid LIKE '%http://oldurl.com%';

/* update all post content */
update wp_posts
SET post_content = REPLACE(post_content, 'http://oldurl.com', 'http://www.newurl.net')
where post_content LIKE '%http://oldurl.com%';

/* update all post meta */
update wp_postmeta
SET meta_value = REPLACE(meta_value, 'http://oldurl.com', 'http://www.newurl.net')
where meta_value LIKE '%http://oldurl.com%';

/* update all options */
update wp_options
set option_value = REPLACE(option_value, 'http://oldurl.com', 'http://www.newurl.net')
where option_value LIKE '%http://oldurl.com%';

Obviously, this will change from site to site and it depends on the table prefix your WordPress install is using and the urls.

So I created the WordPress Site URL Migration Generator to help you generate the SQL code really, really quickly. Just plug in the old url, the new url and your WordPress table name prefix. Check it out and let me know if there is anything missing or incorrect. Or drop me a line if it helped you in any way.

4 comments
  Livefyre
  • Get Livefyre
  • FAQ
JackiLansdowner
JackiLansdowner

In my experience of migrating over 400 the easiest is an export of the Dbase using phpmyadmin and copy wp-content

arafinshaon
arafinshaon

wow its pretty cool actually. Tnx mate.....

themergency
themergency moderator

cool thanks for the link Adam :)

wpmodder
wpmodder

This is super useful, thanks for creating it.

 

One potential "gotcha" to watch out for is the use of serialized arrays by some plugins. Changing the url to one with a different number of characters can cause havoc. This is a script I've used in the past with success (before BackupBuddy accounted for serialization).

http://interconnectit.com/products/search-and-replace-for-wordpress-databases/