RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
The first piece should remove extension to all html files.
Doc - I don't understand at all how that chunk will "remove the extension" to all html files... if I read this correctly, this says:
"If the requested filename is not a directory AND
if the requested file name plus the extension ".html" is a file THEN
Rewrite the ENTIRE URI into the entire uri plus .html"
I see this as adding an extension if it doesn't exist.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule (.*) http:// www. mysite.com/$1 [R=301,L]
Personally, I'd put this as the first evaluation, not the second.
And on another note, I don't like this form, because it is too ambiguous. I'm assuming that, at the very least, you know what domains are hitting your machine, yes? So in fact you know that *mydomain.com should be at this box? Then I'd add a virtual host that captures and bounces everything in front of the real site like this:
<VirtualHost 1.2.3.4:80>
ServerName mydomain.com
ServerAlias *.mydomain.com
DocumentRoot /www/somedir
RewriteEngine on
RewriteRule ^(.*)$ http: //www. mydomain.com$1 [R=301]
</VirtualHost>
This will take everything as is from the first (incorrect) domain and bounce it into your for reals site. I think part of the problem is that you are doing your .html addition BEFORE you are evaluating an incorrect domain... which is why I'd get it out of the way first and out of the flow of the real domain. Additionally, why impose the extra cycles on EVERY SINGLE WEB CALL (including graphics) to evaluate if the domain is wrong? Bounce folks to the right domain in the first place and don't evaluate again.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.mysite.com/$1 [R=301,L]
The third piece should redirect index.html to site root.
This last piece is even more curious to me...
"if the entire request contains (but doesn't necessarily end with) /index.html THEN
Bounce the surfer to the the same domain and append the same URL and call it a 301... What the heck is your intention here? Why do you even need to do this? Is it that you might have /dir/dir/dir/index.html and you want to send people to /index.html? In that case, I'd do something more like this:
RewriteCond %{REQUEST_URI} /.*/index.html$
RewriteRule ^(.*)$ /index.html
and call it a day. Perhaps I'm missing something here - if you could clarify your intentions, or write out a set of rules so they could be evaluated into rewrite rules that'd be a lot easier than trying to just debug your existing code...
note that I put spaces in the above example URLs so that the forum would not make them links