K’s Weblog

Technology and the Interweb for the Real World

Mac G4 towers, second hand... server farm?

Website Redirect with mod_rewrite

August 16th, 2007 · No Comments

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!

  1. Make sure that the permalink structure on the two blogs matches (otherwise things get messy)
  2. Make sure you have access to edit the .htaccess file in your website’s directory
  3. Add the following code to the .htaccess file (most likely at the top):

    RewriteCond %{query_string} ^(.*)$
    RewriteRule ^(.*)$ http://kdmurray.net/$1?%1 [R=301,L]
    My .htaccess file in my WordPress installation now looks like this:

    # 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 WordPress

    I had to comment out the line #RewriteRule . /index.php [L] to make the vanity URLs function correctly.

  4. 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.

Tags: Admin Tools · Blogging · Open Source · Tech Tips

Related Posts

  • Can’t find it? Craig’s List!
  • MacBook: Still Waiting…
  • Miss604 –> $400 for Surrey Food Bank
  • Mac Lab Rat #1 - Global Geek Podcast
  • The Wedding Site



  • 0 responses so far ↓

    • There are no comments yet...Kick things off by filling out the form below.

    Leave a Comment


    Comments links could be nofollow free.

    Cutline by Chris Pearson