Welcome to WebmasterWorld Guest from 54.242.224.250

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Non-WWW to WWW version

     
5:55 am on Jun 30, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 30, 2002
posts: 89
votes: 0


This code is in my htaccess file and it works but I want to be 100% sure that it is correctly coded.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule (.*) [domain.com...] [R=301,L]

6:21 am on June 30, 2009 (gmt 0)

Preferred Member

5+ Year Member

joined:Mar 29, 2007
posts:592
votes: 0


The code is correct. however, you can also add the code to redirect your index file (www.example.com/index.html) to the www.example.com version:

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

7:02 am on June 30, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 30, 2002
posts:89
votes: 0


Sorry I forgot to add, but this is under the code I posted first. Is this the same as what you suggested?

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ [domain.com...] [R=301,L]

8:38 am on June 30, 2009 (gmt 0)

Preferred Member

5+ Year Member

joined:Mar 29, 2007
posts:592
votes: 0


Yes, this is fine.
1:04 pm on June 30, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


The index page redirect should go first --before that hostname canonicalization redirect-- to avoid 'stacked' or 'chained' redirects in the case where "/index.html" is requested from the "wrong" domain.

In general, to avoid problems you should put your external redirect rules in order, from most-specific pattern to least-specific pattern, followed by your internal rewrite rules, again ordered from most-specific to least-specific pattern.

I also suggest the use of the more-robust pattern "^(([^/]+/)*)index\.html$" instead of "^(.*)index.html$" in that index redirect rule, making it:


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

This is more specific, and avoids unexpectedly redirecting --for example-- "newindex.html" or "index.htmlx".

Jim

1:13 pm on June 30, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 30, 2002
posts:89
votes: 0


Thats great, Jim!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members