Moving Your WordPress Site to a New Domain

BACKUP YOUR DATABASE FIRST!

THEN and only then continue with these suggestions..

1. Put up a robots.txt on the new domain with the following contents:

User-agent: *
Disallow: /

2. Copy the database and files to the new domain.

3. Edit wp-config.php to have the right database settings, and add the following lines, replacing sample.com with the right domain:

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

Check this setting:

define ('WPLANG', 'en_US');

4. Now set up your blog install, with the same settings as on the old domain (if you have a caching plugin installed, delete your cache files).

5. Install the Search and Replace application, first rename it (security, this is a bad script to have a hacker see) and then and copy it to your WordPress root directory.

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

This version of search and replace handles serialized php data correctly. Not doing so can trash the database.

Run this script making sure that you leave off any ending “forward slashes” in the Url.

6. Check for an .htaccess file in the root directory. If on exists then review this file. It is common that it contains something like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
</IfModule>
# END WordPress

If your old site had a subdirectory in the url then it would be listed in this example:

# BEGIN WordPress
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /wpress/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /wpress/index.php [L]
</IfModule>
# END WordPress

If you new site does not then you will have to remove the subdirectory (in this case /wpress/) so that it looks like the first example. OR replace with the new subdirectory.

I also found a post that recommended this version:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.+)$ /index.php/$1 [L,QSA]
</IfModule>

 

7. Once you’re done, and you’ve checked everything works twice:

8. Remove the robots.txt file.

9. On your old blog if it was a publicly access site, add the following line to your apache .htaccess or vhost-config:

Redirect 301 /blog/ http://www.newdomain.com/

Another suggested redirect:

If you use the following code in your htaccess, it will redirect all pages to the proper spot in the new domain. As an example oldsite.com/post-about-SEO/ would redirect to newsite.com/post-about-SEO/

RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*oldsite\.com$ [NC]
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]

10. Remove the old blog code and database.

11. Change your FeedBurner account, if you have one, to pick up the correct feed.

12. Remove search and replace script.

This entry was posted in Tips and Techniques, WordPress by John Moore. Bookmark the permalink.
John Moore

About John Moore

John Moore is the co-founder of SonicSpider, LLC in San Diego County, California. John is our head Internet developer, overseeing the direction of our technical services. He has been programming in a variety of languages for more than 25 years, first as the owner of the consulting and system architect/design company, Micro-Phyla Systems, which provided services to enterprise level companies, and then as a principle with SonicSpider LLC. SonicSpider has two primary divisions, SonicWebTech for programming, ecommerce solutions, and general web oriented technical assistance - and RightStart Websites, specializing in WordPress, which provide low cost web packages and website enhancements that can span your needs from "do it yourself" to "do it all for me". John is also a PayPal Certified Developer and has extensive experience with many payment gateway solutions.
View John's Google Profile+