Forum Moderators: phranque

Message Too Old, No Replies

Need confirmation of 301 redirect

         

Reno

6:14 pm on Oct 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Regarding using .htaccess as a site-wide 301 redirect from non-www to www...

I was a little confused after reading this discussion [webmasterworld.com], as the recommended version of the .htaccess went through several variations by the time the thread ended. So just to confirm, is the code below the correct format to use?

Thanks...

====================

RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.html?
RewriteRule ^(([^/]*/)*)index\.html?$ http://example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]

====================

......................

jdMorgan

6:30 pm on Oct 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is one of many "correct" code snippets -- depending on how your site is set up and what you want to do.

This is why mod_rewrite is called "voodoo." It is a tiny 'procedural language' used with regular-expressions, another tiny character-matching language. But the combinaton of these two results in a rather awesome number of application possibilities. While it can be proven that the number of possible incorrect possibilities is extremely large, the number of correct possibilities is also very large. But that's for math majors...

The only way to know if your code is "correct" for your application is to test it thoroughly. You can use the Live HTTP Headers extension for Mozilla browsers to confirm a proper 301 HTTP response in each case, observe the browser address bar as redirects occur, and check whether the results are what you desire. That's the only way to know if it's correct for you.

Jim

Reno

8:43 pm on Oct 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you Jim -- as you noted, I had copied the posted 301 code from your participation in that thread. As usual, your explanation was very helpful in trying to understand all this stuff...

.......................