Forum Moderators: phranque
AddType application/x-httpd-php .html
AddType text/x-server-parsed-html .htm .html
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
but this only does the example.com and not the www.example.com/index.html
Can someone help me with some code please please?
thanks
First. That code only works for the single index file located in the site root. You should fix this for all folders at any level. There's example code posted in many prior threads.
Second. If you place this redirect after your non-www to www redirect then you create an unwanted redirection chain for a non-www request that contains the index filename.
To fix this, use the example code posted in earlier threads, and place that code before the general non-www to www redirect.
Be aware that your non-www to www redirect code can be improved in several subtle ways too. Several prior threads discuss the reasons.
# 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]