问题
Currently, I am using the below code to remove the word 'index' in my urls - however, the issue is that it allows for two versions: one without and one with [the word] - hence, I have referenced the one without (in the HTML) - but the user still might type the one with the word.
How can I completely wipe the word 'index' from the index page:http://example.com/index[.html]
goes to http://example.com/index
but should really go to http//:example.com
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/index$ $1/ [R=301]
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
回答1:
You can use:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index [NC]
RewriteRule ^(.*?)index(?:\.html)?$ /$1 [L,R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/index$ $1/ [R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ $1 [R=301,L]
来源:https://stackoverflow.com/questions/30684749/how-to-remove-the-word-index-in-the-url-htaccess