RewriteRule index.html to root in htaccess: which code is better? And why? What do they do different? Thanks for your thoughts! I’m getting rid of my duplicate pages. Basically which code is cleanest that will do the job and slow the server response down the least. I do wish to use code that takes care of all my index files in all subdirectories. And I only have to say RewriteEngine On once right?
I got rid of the non-www with this. I believe this is clean. If not let me know…
# 301 permanent redirect from non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
Curently I’m using this code to rewrite the index.html to www.mydomain.com/…
# rewrite index.html to root
RewriteRule ^index\\.html$ http://www.mydomain.com/ [L,R=301]
But then I’ve seen various different versions of this around the web. I think I am to understand that it takes care of all indexes in all directories but it also has the “RewriteCond” line. Whats that do?? FYI I do have other rewrite code in my htacces to if that matters any.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\\ /.*index\\.html\\ HTTP/
RewriteRule ^(.*)index\\.html$ [b]http://www.example.com[/b]/$1 [R=301,L]
A little cleaner it seems but does it work the same?
RewriteCond %(THE_REQUEST) ^[A-Z] {3,9}\\ /.*index\\.html\\ HTTP/
RewriteRule (.*) index\\.html$ /$1 [R=301,L]
And now what is {IS_SUBREQ} false? Too many ways to skin a cat here
RewriteCond %{IS_SUBREQ} false
RewriteRule ^index\\.(php|html?)$ http://www.martin-thoma.de/terminplaner/ [R=301,L]