direct all webpage requests with .index.html to /
开发者_运维技巧I want to direct all requests for any URL that ends with index.html to /. I have one domain on the server.
Example:
- If someone wants "www.thissite.com/index.html--it is directed to www.thissite.com/. AND
- if someone wants "www.thissite.com/anyword/index.html"--it is directed to www.thissite.com/. AND
- if someone wants "www.thissite.com/folderdoesntexistonthissite/index.html"--it is directed to www.thissite.com/.
What is the .htaccess code that would enable this? (Both the rewritecondition and rewriterule)
This doesn't quite do the job:
RewriteCond %{THE_REQUEST} index\.html [NC]
RewriteRule index\.html$ http://www.thissite.com/$1 [R=301.L]
You could try this (without RewriteCond):
RewriteRule /index\.html$ http://www.thissite.com/ [R=301,NC,L]
Maybe the Error was the Period in [R=301.L]
.
You will need to use %{REQUEST_URI}
variable to match in RewriteCond otherwise Apache strips out starting /
in RewriteRule. Use below code in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_URI} ^.*/index.html$ [NC]
RewriteRule . / [R=301,L]
精彩评论