Forum Moderators: phranque
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]
Without a preceding RewriteCond looking at THE_REQUEST you'll have an infinite redirect loop for index requests.
RewriteRule ^(.*/)?index\.html?$ /$1 [R=301,L]
I just tested it, but there was no infinite redirect loop...
Do you mean the substitution string should have the full hostname? Can you explain the reasons behind this suggestion?
(.*) or .* or the pattern ends with (.*)$ then .* is not appropriate. Use a more specific pattern that will parse left to right in one pass.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^$ if the goal is to match any string, then matching on any character is the perfect tool for the job
Are you saying that when you tried this yourself, you ended up in a redirect loop?
It will match as many times as possible while still allowing the rest of the pattern to match.
# 301 permanent redirect index.html(htm) to folder with exclusion for addon domains
RewriteCond %{HTTP_HOST} !(addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html?$ http://www.maindomain.com/$1 [R=301,L]
# 301 permanent redirect non-www (non-canonical) to www with exclusion for addon domains
RewriteCond %{HTTP_HOST} !(addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com)
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.maindomain.com/$1 [R=301,L]
If you don't know/have the answer then be a man about it and admit it.
Wow the quoting tech in the forum is top notch.