How To Move Your WordPress Blog The SEO Friendly Way

wp-iconI recently had the urge to move my 4 year-old WordPress blog from JasonHendricks.com over to a fresh WordPress install on this site, and I wanted to use a newly created directory named /blog/. Why? I didn’t like the layout of the old site at all, plus it makes more sense to blog here than from my own personal domain.

I knew this would be a challenge from a 301 redirect perspective, due to the fact that I decided to go with a completely different permalink structure AND have WordPress installed in its’ own directory instead of the web root like it was on the old site. So I figured I’d share my experiences…

If you need instructions on how to move your entire WordPress install to your new host/domain, check out the following pages depending on your situation:

Moving WordPress

Move Your WordPress Blog To A New Domain In 10 Steps

How To Move Your WordPress Blog to a New Domain

How To Move From WordPress.com To WordPress.org

The actual moving part was extremely easy, since I didn’t care about the theme, categories, tags, or any extra data from installed plugins remaining intact. In my particular case, I wanted to migrate all posts and comments ONLY, so that’s what I did.

The built-in WordPress import/export functionality didn’t work at all for some reason, so I had to find another way. The next best way to do it (if you’re comfortable working with the database) is below:

Moving Comments and Posts ONLY To A Fresh WordPress Install

  1. Just to be sure everything goes according to plan and the table structures match, verify that both WordPress installs are the exact same version. Upgrade if not.
  2. Log into the old WordPress MySQL database via phpMyAdmin (if you have forgotten or don’t know your login details, just open wp-config.php which is in the root folder of your blog…it contains all your db info), then select your database from the available options.
  3. Export the posts table to a file (also called a sqldump), then save the text file.
  4. Export the comments table to a file, then save the text file.
  5. Now log into the new WordPress MySQL database, select the database, then drop the comments and posts tables.
  6. Go to import and import each sqldump (text files) created from the old WordPress database.
  7. That’s it!

Great, but you’re not done. You still need a way to permanently redirect all visitors, search engines, and inbound links to the new site without just redirecting everything to the home page.

If you’re keeping the same permalink and directory structure this is very easy, just add this to the .htaccess file on the old site:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^youroldsite.com [NC] RewriteRule ^(.*)$ http://www.yournewsite.com/$1 [L,R=301]

NOTE: The ‘(*.)$’ says that we’ll take anything that comes after ‘http://www.youroldsite.com‘ or ‘http://youroldsite.com‘ and append it to the end of ‘http://www.yournewsite.com‘ (that’s the ‘$1’ part), and redirect to that URL.

Important Notes About .htaccess Redirection

  • Verify that you’re not overwriting an old .htaccess file, sometimes servers place one there for your custom 404 pages, existing applications, etc.
  • Always be sure to upload .htaccess files in ascii mode, uploading as binary won’t work.
  • .htaccess will not work if you’re on a Windows Server (IIS).
  • Since some operating systems don’t allow you to make a file without something before the ‘.’, you may need to save it as htaccess.txt and rename it once you’ve uploaded it.
  • Make sure your ftp program will show .htaccess files (FileZilla does and is free).
  • Make sure you triple check your changes. Test the server headers to make sure you see a 301 (that means it’s permanent) not a 302 (temporary) unless you are absolutely sure you really mean temporary.

Unfortunately this was not the case for me. Everything went very smoothly when it came to moving the site itself, but now I need to redirect all old page names to the new URL and permalink structure.

In the past, I had two options here. I could create a very lengthy .htaccess file containing entries that map all old pages to new ones, but this would take forever so that’s out. I could use regular expressions with mod_rewrite in .htaccess to create rules to handle the 301 redirects, but that would be time consuming/complicated as well. What to do?

Luckily there’s a WordPress plugin called Redirection to do this for you. Not only will it save you tons of time, it also automatically prevents headaches for you down the road. Once installed, I was able to create 301 redirects with regular expressions to take care of everything using a simple admin panel:

Redirection Plugin Configuration

Let’s run through these quickly, shall we?

Redirections Sorted By Order

  1. /page/(.*)/ => http://www.tidalwavemedia.com/blog/page/$1 – redirects all requests for paginated URLs to their corresponding paginated URL on the new site, for example ‘http://www.jasonhendricks.com/page/5/‘ to ‘http://www.tidalwavemedia.com/blog/page/5/
  2. /(d*)/(d*)/ => http://www.tidalwavemedia.com/blog/$1/$2/ – redirects all requests for date-based URLs such as archives to their corresponding URL on the new site, for example ‘http://www.jasonhendricks.com/2006/06/‘ to ‘http://www.tidalwavemedia.com/blog/2006/06/
  3. /(.*)/(.*)/ => http://www.tidalwavemedia.com/blog/$2.htm – redirects all requests for blog posts using the old permalink structure of /%category%/%postname%/ to their corresponding URL on the new site using the permalink structure of /%postname%.htm (notice the category is stripped from the URL), for example ‘http://www.jasonhendricks.com/seo-advice/how-not-to-be-seen-by-google/‘ to ‘http://www.tidalwavemedia.com/blog/how-not-to-be-seen-by-google.htm
  4. /(.*)/ => http://www.tidalwavemedia.com/blog/$1 – redirects all requests for blog pages to their corresponding URL on the new site, for example ‘http://www.jasonhendricks.com/about/‘ to ‘http://www.tidalwavemedia.com/blog/about/
  5. / => http://www.tidalwavemedia.com/blog/ – redirects all requests for the old parent domain name to the new parent domain, for example ‘http://www.jasonhendricks.com‘ to ‘http://www.tidalwavemedia.com/blog/

NOTE: Be sure to test using your old URLs in your browser and verify that the order of redirection is correct. Also note that ‘http://www.youroldsite.com/wp-admin/‘ will no longer work after you’ve configured Redirection as I have. To login to your old site to check redirection/error logs and view stats, use ‘http//www.youroldsite.com/wp-login.php‘.

For more on regular expressions, how to use them with Redirection, and to download the plugin, scroll through the plugin author’s page:

WordPress Redirection Plugin

Pretty cool, right (OK…maybe not cool, but you know what I mean)? As if that’s not enough, here are several more features of the Redirection plugin worth noting:

  • 404 error monitoring – captures a log of 404 errors and allows you to easily map these to 301 redirects
  • Full logs for all redirected URLs
  • Automatically add a 301 redirection when a post’s URL changes
  • Apache .htaccess is not required – works entirely inside WordPress
  • Redirection methods – redirect based upon login status, redirect to random pages, redirect based upon the referrer!

If you find this plugin incredibly useful like I did, be sure to donate to the author and help support free software.

Related Post:

301 Redirect Example When Using Wildcard DNS For Subdomains

«

Comments

Leave a Reply

Quick Contact Form

    Uncheck box to submit
    (please prove you're human)

    RSS feed

    Enter your email address to subscribe and receive notifications of new blog content by email:

    Content Calendar
    Free Consultation