homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Basic, Generic .htaccess for non-www to www conversion
includes redirecting links that point to "index.html" to point to "/"

5+ Year Member

Msg#: 3947203 posted 9:13 pm on Jul 6, 2009 (gmt 0)

Does anyone see any issues with the .htaccess code below(specifically loss of page rank do to a double+ redirect, or infinite loop problems)... or any problems at at?

The idea is to set "index.html" as the default home page. Then any requests that come in for www.example.com/index.html are redirected to www.example.com/. The last part is to make sure that no matter how badly formed the request is, that it will be directed to use the "www" nameing convention -> "www.example.com/"

Thanks for your feed back on this:

DirectoryIndex index.html

Options Indexes FollowSymLinks Includes
RewriteEngine on
# Externally redirect requests for index.html in any directory to "/" in that directory
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.example.com/$1 [R=301,L]
# Externally redirect requests for *all* non-canonical hostnames to canonical hostname,
# including case errors and appended FQDN indicator and/or port numbers.
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

[edited by: RedWine at 9:13 pm (utc) on July 6, 2009]



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

Msg#: 3947203 posted 9:53 pm on Jul 6, 2009 (gmt 0)

There is no potential for a double redirect here, because the most-specific rule is executed first and forces both domain and index canonicalization.

Hostnames in the FQDN form and/or including a port number are not "badly-formed," they are simply non-canonical.

Unless you wish the server to produce a directory listing of all files in subdirectories which do not include an index.html file, do not use "Options Indexes".

If you are worried about double redirects, use the Live HTTP Headers add-on for Firefox/Mozilla browsers to test your code.



5+ Year Member

Msg#: 3947203 posted 10:31 pm on Jul 6, 2009 (gmt 0)

Thanks alot jdMorgan - really appreciate the help!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved