I 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:
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
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
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:
Let’s run through these quickly, shall we?
Redirections Sorted By Order
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:
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:
If you find this plugin incredibly useful like I did, be sure to donate to the author and help support free software.
Related Post:
« Help Wanted: Search Engine API Programmer
Comments