Welcome to WebmasterWorld Guest from 54.161.135.168

Forum Moderators: Ocean10000 & incrediBILL & phranque

Basic, Generic .htaccess for non-www to www conversion

includes redirecting links that point to "index.html" to point to "/"

   
9:13 pm on Jul 6, 2009 (gmt 0)

5+ Year Member



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]

9:53 pm on Jul 6, 2009 (gmt 0)

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



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.

Jim

10:31 pm on Jul 6, 2009 (gmt 0)

5+ Year Member



Thanks alot jdMorgan - really appreciate the help!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month