Forum Moderators: phranque

Message Too Old, No Replies

non-www and index.html redirects.

Is my code correct?

         

Perfection

9:11 pm on Jun 16, 2006 (gmt 0)

10+ Year Member



I want to:

A) Make requests for domain.com become www.domain.com
B) Make requests for index.html become www.domain.com

After reading the forums, I think this is the code I need:

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

Does this all look correct for what I'm trying to do?

Thanks in advance.

[edited by: jdMorgan at 10:06 pm (utc) on June 17, 2006]
[edit reason] example.com [/edit]

jdMorgan

4:50 pm on Jun 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It looks OK, but be aware that this forum removes a required space between "}" and "!", and also that you should reverse the positions of the two rules, so as to avoid a double 301 redirect if "example.com/index.html" is requested:

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

Jim

Perfection

9:59 pm on Jun 17, 2006 (gmt 0)

10+ Year Member



Just switched them. Thanks Jim.