Latest: buggy behaviour of parent:: in PHP 5.3.3

Content with Style

Web Technique

301 redirect with mod_rewrite

by Pascal Opitz on April 25 2007, 09:10

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]

Comments

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

    by Saptarshi on May 2 2007, 04:51 - #

  • @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.

    by Pascal Opitz on May 2 2007, 10:46 - #

  • I am pretty sure this creates an infinite loop when using Word Press redirection plugin.

    by Jason Grant on April 9 2009, 15:39 - #

  • Jason, keep in mind that the mod_rewrite execution happens before PHP.

    Whether or not Wordpress then redirects to something that gets caught by the rewrite rule again, I couldn't possibly answer.

    by Pascal Opitz on April 9 2009, 15:51 - #

Leave your comment

Comments are moderated.
Tags allowed: a, strong, em, code, ul, ol, li, q, blockquote, br, p

Advertisement
Advertisement