WordPress migration to new domain: Keep your SEO with these 301 Redirect Tips

Today I branched studio.stevenchu.com off to stevenchustudio.com. This is how I migrated one WordPress.org installation to another wordpress.org installation.

WordPress Migration

First, I transferred all my files using my web host ICDsoft‘s FTP migration tool.

Second, I used phpMyAdmin (on my web host ICDsoft‘s control panel) to download my MYSQL database files for my blog (all my blog entries and settings) to a zip file. I opened the zip file, and opened the database file with a text editor and did FIND AND REPLACE.
I found every entry for: studio.stevenchu.com
Replaced all instances with: stevenchustudio.com

I saved file, and rezipped it. That way all my database links and files are updated and pointing to the right place. If you don’t update your urls, your wordpress login page will try to send you to your old website, and you’ll never get in!

Third, I created a new MYSQL database on my new stevenchustudio.com site. I opened stevenchustudio.com‘s copy of wp-config.php file and updated my MYSQL database name with what I just created, username, and password- so that it could connect.

Fourth, I logged into phpMyAdmin on stevenchustudio.com and upload my modified database file. All done!

WordPress Redirect All URLs and images for Google with 301 Redirect

First I checked my new stevenchustudio.com site to make sure everything worked properly. I saw that some of my theme settings were lost, but because I had the wordpress for studio.stevenchu.com open, I just manually copied/transcribed over each setting.

To redirect all my pages, I used this great tip from Schoonology:

Add this code to your functions.php file on your old blog, to tell it to redirect the base URL to your new site with the same page URL endings.

function conditional_redirect()<br>
			if ($_SERVER["SERVER_NAME"] != 'stevenchustudio.com')<br>
				wp_redirect('http://stevenchustudio.com' . $_SERVER["REQUEST_URI"], 301);<br>
		add_action('get_header', conditional_redirect);<br>

From Schoonology: “the conditional checks to see if we’re already where we want to be. If we are, then there’s no reason to redirect someone to it, is there? Otherwise, perform the redirect.”

So that took care of all the URLS!

Redirect your wordpress images folder

Now for my uploaded wordpress images which are bringing me hits on google! To have these mirrored, I edited my OLD WEBSITE’s (studio.stevenchu.com) .htaccess file. NOT THE NEW ONE. I added one line of code inside the

&lt;IfModule mod_rewrite.c&gt;


The technique is called RedirectMatch with wildcards ^. You can google or see a more complicated example of it here.

This line will 301 Redirect the Entire Image Uploads Directory. note that the URL begins with /wp-content because I installed my wordpress in my main directory. (Note: If you stored yours in a folder, make sure to include that ie /blog/wp-content/…)

RedirectMatch 301 /wp-content/uploads/(.*) http://www.**YOURDOMAIN**.com/wp-content/uploads/$1<br>

This is my final htaccess file with the one line of code added:

# BEGIN WordPress<br>
&lt;IfModule mod_rewrite.c&gt;<br>
RewriteEngine On<br>
RewriteBase /<br>
RewriteRule ^index\.php$ - [L]<br>
RewriteCond %{REQUEST_FILENAME} !-f<br>
RewriteCond %{REQUEST_FILENAME} !-d<br>
RewriteRule . /index.php [L]</p>
<p>RedirectMatch 301 /wp-content/uploads/(.*) http://stevenchustudio.com/wp-content/uploads/$1</p>
<p># END WordPress<br>

Presto, URLs forward, and any images people try to access from google images etc gets instantly forwarded.
Google is all good to go! Hope this helps!!

Leave a Reply