I would like to get开发者_开发技巧 rid of all the file extensions on my site. Except when they are on the index i would like it to say nothing...
change this foo.com/index.html
to this foo.com/and when the user goes to another page like foo.com/contact-us.html
it will be foo.com/contact-usRewriteEngine On
RewriteRule ^ this is where i get confused :(
Thanks in advance!
Try these rules:
RewriteRule ^index\.html$ / [L,R=301]
RewriteRule (.+)\.html$ /$1 [L,R=301]
I'd use a slightly different method:
RewriteCond %{REQUEST_FILENAME}\.html -f # if request.html exists and is a file
RewriteRule ^(.+)$ $1\.html [QSA] # then rewrite to that file.
It doesn't have to be so complicated, apache has an option to accomplish what you want:
Just add this rule to your .htaccess and /contact-us/ will automatically be rewritten to contact-us.html:
Options MultiViews
That's it!
精彩评论