目前,我正在使用以下代码删除我的网址中的'index'一词 - 然而,问题是它允许两个版本:一个没有,一个带[单词] - 因此,我引用了一个没有(在HTML中) - 但用户仍然可以输入带有单词的那个。
如何从索引页面完全删除“索引”一词:http://example.com/index[.html]
转到http://example.com/index
,但应该转到http//:example.com
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/index$ $1/ [R=301]
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
答案 0 :(得分:0)
您可以使用:
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]