Warning: This post is going to get a bit technical…
This afternoon, I was checking out my Google Analytics statistics and realized that I was still getting quite a bit of traffic to the old blog at krell.cellsandbytes.net. I was wishing that these people would be kind enough to click on my new links on the new blog… but alas this was not the case.
So I set about trying to figure out how to make all of my old blog pages redirect to the ones on the new site. For your convenience, I’ve documented the steps involved in case you need to do this too!
- Make sure that the permalink structure on the two blogs matches (otherwise things get messy)
- Make sure you have access to edit the .htaccess file in your website’s directory
- Add the following code to the .htaccess file (most likely at the top):
My .htaccess file in my WordPress installation now looks like this:
RewriteCond %{query_string} ^(.*)$
RewriteRule ^(.*)$ http://kdmurray.net/$1?%1 [R=301,L]# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]RewriteCond %{query_string} ^(.*)$
RewriteRule ^(.*)$ http://kdmurray.net/$1?%1 [R=301,L]
</IfModule>
# END WordPressI had to comment out the line #RewriteRule . /index.php [L] to make the vanity URLs function correctly.
- Test your website
I was able to make this work for static pages (/index.php) as well as the vanity URLs (/2007/06/15/flickr-vs-photoblog/) and everything seems to be working swimmingly. This will successfully re-route all the traffic from links, or bookmarks to my old site, and ensure people land on the right page on the new site.
Credit: Thanks to jdMorgan a moderator at webmasterworld.com for the original rules & regex.