如何删除单词';指数';在url[.htaccess]中?
目前,我正在使用下面的代码删除我的URL中的“index”一词-然而,问题是它允许两个版本:一个没有,一个有[这个词]-因此,我引用了一个没有(在HTML中)-但用户仍然可能键入一个有这个词 如何从索引页中完全删除“index”一词:如何删除单词';指数';在url[.htaccess]中?,.htaccess,mod-rewrite,redirect,url-rewriting,file-extension,.htaccess,Mod Rewrite,Redirect,Url Rewriting,File Extension,目前,我正在使用下面的代码删除我的URL中的“index”一词-然而,问题是它允许两个版本:一个没有,一个有[这个词]-因此,我引用了一个没有(在HTML中)-但用户仍然可能键入一个有这个词 如何从索引页中完全删除“index”一词:http://example.com/index[.html]转到http://example.com/index但实际上应该转到http/:example.com RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.
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]
您可以使用:
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]
您可以使用:
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]
不幸的是,它对我不起作用;你也在子域上测试过吗?试试我更新的答案。你用来测试的完整URL是什么?不幸的是,它对我不起作用;你也在子域上测试过吗?试试我更新的答案。你用来测试的完整URL是什么?不幸的是,它对我不起作用;你也在子域上测试过吗?试试我更新的答案。您用于测试的完整URL是什么?