tutskid.com

How to Move a WordPress Site to a New Domain

A few days ago I announced that our site has moved from a subdomain under the name “tutorials.triptripper.com” to its new permanent top level domain, at TutsKid.com. I have mentioned in that post that I plan to publish the process involved in moving this blog to a new domain.


So, today, I finally decided to write a WordPress tutorial which will help anyone to move a WordPress blog to a new domain with zero downtime and without loosing backlinks or indexed pages. Of course you want to keep all backlinks and link structure untouched.

Here are the steps you’ll want to take when moving to a new domain name. Make sure you read and understand it before you implement it because any mistake can bring you very serious trouble as you may loose your traffic or search engine positions.

How to move a WordPress site to a New Domain

Current Domain:

1. Backup the WordPress files and database of your old domain

There are 2 ways to backup your wordpress database. Using phpmyadmin or the export option in WordPress dashboard. In my case I always use phpMyAdmin in backing up database. Follow the methods below:

Once you have logged in to PHPMyAdmin, select the database for your existing WordPress installation from the list on the left.
select the database
Clicked the Export tab at the top of the window.
step 2 backup database
Make sure that the radio button for the ‘Quick’ export method is selected. Click the ‘Go’ button to download a .sql file of your current database table structure along with all of your existing data. You’ll want to save the file somewhere on your hard drive where you can find it a little later.
step3 backup database
If you choose to export the data in the form of .xml using import/export option, you can find the Export option under the Tools tab in your WordPress dashboard. Choose all content then click ‘Download Export File’ and it will backup your entire content and save it in the xml format. Save it and keep it in a location that you will remember.

2. Download wp-content Folder

Download wp-content folder on to your hard drive via FTP. Place it somewhere you can find it later. This should grab all of your existing plugins, themes, images, uploads etc. If you have set up any sub domain or subdirectory then download same folder too. You’ll also want to download your favicon and Robots.txt file if you have them.

New Domain:

1. Install WordPress on the New Domain

You can do it manually or via Fantastico. Then update all of your settings to match the old domain.

2. Upload wp-content Folder in the fresh WordPress install

Login to your new domain cpanel via ftp and upload wp-content folder. Just override the existing wp-content folder from your fresh WordPress install.

3. Activate Theme and Plugins

Ensure you have the same theme and same plugins activated as the old domain name.

4. Import Your Database

Log in to the phpMyAdmin interface, select the new database from the list on the left and click the ‘Import’ tab at the top of the window.

‘Choose’ and select the file you just downloaded from your old domain containing your database. Then click the ‘Go’ button to import your data.
import backup database
If your importing .xml file, you can find the Import option under the Tools tab in your WordPress dashboard. Select WordPress, it will ask you to download WordPress Importer plugin, download it from your dashboard and select .xml file that was exported and saved on your hard drive earlier.

Editing the wp-config.php file:

If the database imported still has the old website URL in it, you need to add these lines to the wp-config.php file:

define(‘WP_SITEURL’, ‘http://www.yournewdomain.com’);
define(‘WP_HOME’, ‘http://www.yournewdomain.com’);

You also need to include the correct information for your new database:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'your_dbname-here');
/** MySQL database username */
define('DB_USER', 'your_username_here');
/** MySQL database password */
define('DB_PASSWORD', 'your_password_here');
/** MySQL hostname */
define('DB_HOST', 'localhost');


Replace and update Old URL’s with new one:

Once the blog has been moved and all files copy over on new domain, you will need to fix URLs of the WordPress images, comments, posts and pages. Open phpMyAdmin and use the following SQL commands to fix all internal links to own blog in all WordPress images, posts and pages:

UPDATE wp_posts SET post_content = REPLACE(post_content,'http://www.old-domain.com/','http://www.new-domain.com/')

To update the images URLs in the media library enter the following SQL command:

UPDATE wp_posts SET guid = REPLACE(guid,'http://www.old-domain.com','http://www.new-domain.com')


5. For subdomains or subdirectories

Upload and setup your sub domains and sub directories using the same steps above.

6. Redirect traffic to your new domain

Redirect your old blog url to new domain that is called 301 redirect via .htaccess. Put this in the old site’s .htaccess file – which you will find on the root of the site.

Backup your .htaccess file and change it’s content to something similar to this:

WWW version:

#change domain names for an existing site whilst avoiding any www and non-www canonical problems,
#www version
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.old-domain\.com$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^old-domain\.com$
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Non-WWW version

#Non-www version
RewriteEngine On
RewriteCond %{HTTP_HOST} !^old-domain\.com$
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.old-domain\.com$
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]

301 redirect for subdomain blogs – which you will find on the root of the subdomain site.

RewriteCond %{HTTP_HOST} ^subdomain\.old-domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [QSA,R=301,L]


That’s it! Web browsers and search engines visitors should be redirected without even noticing it. You will temporary loose your pagerank and backlinks visibility but it will be back the next pagerank update. So it’s still a good practice to get people to update the links in their blogs or posts to the new domain URL.

Finally, change the feed URL at Feedburner, add new domain at Google Webmaster Tools and add sitemap so Google will crawl data quickly.

If you enjoyed this post, please share it with your friends. Recommend, Tweet, Plusone or Pin it.

About Marvie Pons

Marvie is a freelance web designer and developer, who specializes in WordPress themes and have written quite a few WordPress plugins. He frequently writes on topics including web design, search engine optimization, web hosting, and WordPress tutorials. [Read More …]

Follow him on Twitter and Pinterest | Connect with him on Google+

Sign up to get more posts like this delivered directly to your inbox!

One comment on “How to Move a WordPress Site to a New Domain

  1. Wow! You make it seem so easy – I’ve moved wordpress sites a few times and its been an absolute nightmare, but I must admit, I had no idea what I was doing. I have half a mind to just try your methods and bookmark/print the heck out of this post because I needed it like yesterday ;) . Thanks!

Leave a Reply

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