301 redirect with mod_rewrite

by Pascal Opitz

published 25 April 2007


So I changed my domain name from .de to .com. But wasn’t there something whereas Google would punish double-posted content with pagerank 0? That’s where a 301 redirect comes in, as neatly explained on this tutorial by GNC Web Creations. The straight forward way to point an old domain to a new one would be putting this into the .htaccess:

Redirect 301 /foo http://foobar.com/foo

OR

Redirect permanent /foo http://foobar.com/foo


Now in my particular setting it was a bit more difficult, the domain was pointing to the same directory on the same server. And all that on a GUID managed system, so no fiddling around in the httpd.conf files.


Thankfully the whole issue is easily solved utilizing the reg exp based rules of mod-rewrite, examining the HTTP_HOST of the request:

RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(www.)?example.de
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]

Comment

  1. i think it would have been more helpful if you would have explained the whole process in little more details.

    I recently did a post as http://seo-kolkata.blogspot.com/2007/04/301-redirect-comprehensive-guide-to-url.html where I explained both 301 and 302 but provided the codes mainly for 301 redirection as that is the most SEO friendly option.

    I have listed the script for redirection in ASP, PHP, ASP.Net, VB.Net and JSP/Java.

    my objective was to provide a guide for the not so techsavvy users.

    Would appreciate your feedback on the post.
    Saptarshi    2 May, 10:51am    #
  2. @Saptarshi:
    I think more details are very very often more helpful. However, this blog section is meant to be understood as quick messages about what we deal with, without having the time to write full article on them.
    Let’s face it: If I would have to write more on this I just couldn’t fit it into my mad busy day.
    Pascal Opitz    2 May, 4:46pm    #

Have your say

If your comment doesn't show up straight away, please don't be offended - we're not censoring, we are just trying to keep out all the viagra and poker ads. Thanks to an explosion of spam all comments are held for manual green-lighting.

name Remember
email
http://
Message <?>

Quick links

Other people's articles that we think you might be interested in: