24/7 HUMAN WORDPRESS WATCH · SAN DIEGO, CA · SINCE 1998
HackGuard.com Managed WordPress Security with Heart
TOPIC CLUSTER · BACKUPS & INFRASTRUCTURE

How to Migrate WordPress to a Different Domain Name Without Losing SEO

Jim Walker By Jim Walker, The Hack Repair Guy™ Updated Topic: WordPress Backups, Hosting Isolation & Migrations
Quick Answer

Moving WordPress to a new domain requires copying both your files and MySQL database, running a serialized-safe search-and-replace on the old domain name so widget and theme settings stay intact, and adding permanent 301 redirects.

How to Migrate WordPress to a Different Domain Name Without Losing SEO
Checklist for moving a WordPress site to a new domain name, updating serialized database URLs safely, and setting up 301 redirects.

Why this matters for your WordPress site

You've purchased a number of domain names for your website. And you wish to assign another of your domain names as the main domain people see in the web browser location bar when they visit your website.

Your client has asked you to update their existing theme but would prefer you not edit their live website. Staging the website in a subdirectory within the current hosting account will allow you to work with the existing theme in a safe environment.

You would like to move your website to another web host, but test your website at the new host before pointing the domain name to the new hosting account.

Start by making a backup of your existing website files and database.

Step-by-step setup and recommendations

Backing up files and databases within cPanel is as simple as clicking Backup, then clicking two links:

Download a Home Directory Backup

then Download a MySQL Database Backup

Once you have a solid backup of files and database:

Set up a staging subdomain within your web hosting account like staging.at-your-domain.com, or use a different domain name entirely. If you are installing your WordPress site within a subdirectory on a cPanel server, click the Addon Domains button. If you are installing your WordPress site into the main directory on a cPanel server, click the Aliases button, and you'll be all set in two clicks.

Common mistakes to avoid

Then install WordPress into the new account or directory.

Rename the wp-config.php file for now. We are doing this so that when you recover your site files you do not inadvertently overwrite the newly set up wp-config.php file.

Upload and extract your backup of files within to your staging directory.

Delete the wp-config.php file you just copied over from the live site and rename the wp-config.php file renamed in (3) above back to wp-config.php

The how to import a database part of the process can be a bit tricky the first time around. Since you already have a working wp-config.php in place and a working database in place, use your FTP or your web host's file editor to view the contents of your wp-config.php in order to obtain the database name. Log into your PHPMyAdmin. Click on the database name at left. This will display a list of tables. Check all tables, choose the Drop option, then Go to drop all the tables.* *All you are doing here is removing the existing database tables in preparation for import. And finally, click the Import option at the top, Choose File, select that database you downloaded to your computer earlier, then click Go.

If all goes well with the import you will have completed the initial staging setup process.

<?php
define('WP_HOME',"http://{$_SERVER['SERVER_NAME']}/");
define('WP_SITEURL',"http://{$_SERVER['SERVER_NAME']}/");

If your website uses an SSL certificate, use https:// instead of http:// in both lines.

* The WordPress.org website covers editing wp-config.php fairly nicely, in case you are interested in reviewing the technical bits.

Then visit your migrated website. 99% of the time the two lines of text above are all you need to do!

"So what's this magic going on behind the scenes" you may ask?

Ok, I'll let the rabbit out of the hat. The guts of your WordPress settings are maintained in the wp_options table. All this magical bit of gray text in #2 above does is override your siteurl settings in your database. Presto magico!

The original website with website address: pharm.tvsecure.net

I copied the same website into a subdirectory of the same account for staging purposes, at: /pharm-staging.tvsecure.net

and set the domain name pharm-staging.tvsecure.net to point to that subdirectory.

However, we had one obvious problem. Because the staging website was copied from pharm.tvsecure.net any attempt to visit pharm-staging.tvsecure.net resulted in an immediate redirect back to the original pharm.tvsecure.net domain.

Well, that's annoying. So, following step #2 above, I simply copy/pasted the two lines shown above into the top of my /pharm-staging.tvsecure.net/wp-config.php file, like this:

The result? When I go to pharm-staging.tvsecure.net the new website address pharm-staging.tvsecure.net I had staged earlier within the directory: /pharm-staging.tvsecure.net appears nicely like this:

Well, that about covers the basics of migrating a WordPress website to a different domain name by copy/pasting two lines of text.

If you have suggestions or additions to this WordPress staging or migration related article please be sure to email me anytime, jim at HackRepair.com

Enjoy!

Frequently asked questions

What is the fastest way to fix or prevent this issue on my WordPress site?
Moving WordPress to a new domain requires copying both your files and MySQL database, running a serialized-safe search-and-replace on the old domain name so widget and theme settings stay intact, and adding permanent 301 redirects.
Can HackGuard.com handle backups & hosting for my WordPress site?
Yes. For $14.95/month (or $49.85/month for up to 10 sites), Jim Walker and the HackGuard team perform a 9-point manual security and database overhaul in Week 1, test all core and plugin updates weekly by hand, maintain 60-day offsite cloud backups, and back your site with a free HackRepair.com cleanup guarantee. Call Jim directly at (619) 479-6637.
Jim Walker, The Hack Repair Guy

Written and reviewed by Jim Walker, The Hack Repair Guy™

Jim Walker has protected and repaired WordPress websites since 1998. Want Jim to handle your WordPress security, weekly updates, and 60-day offsite cloud backups for 50 cents a day?

Client Video Story