重定向规则不区分大小写

时间:2014-09-07 13:24:20

标签: .htaccess mod-rewrite mod-speling

我有网址重写规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/sites/
RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [NC,L]

调用此网址时:http://example.com/suyash

它在内部调用http://example.com/sites/suyash,但仅将URL保留为http://example.com/suyash。请注意,文件夹sites/suyash实际存在

我面临的问题是,当我调用网址时:http://example.com/Suyash(大写)会显示404错误。

当我使用mod_speling模块并将以下内容添加到代码中时:

CheckSpelling On

现在当我致电http://example.com/Suyash时,它会将网址更改为http://example.com/sites/suyash

如何才能将其从http://example.com/Suyash更改为http://example.com/suyash

2 个答案:

答案 0 :(得分:0)

mod_speling将重定向浏览器以修复拼写,没有办法避免这种情况。我唯一能想到的是尝试使用P标志在内部代理请求。您需要确保已加载mod_proxy。我没有测试过这个:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/sites/
RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [NC,L,P]

答案 1 :(得分:0)

我会说保持CheckSpelling关闭。

然后让你的规则如下:

CheckSpelling Off
RewriteEngine On
RewriteBase /

RewriteCond %{DOCUMENT_ROOT}/$0 -f [NC]
RewriteCond %{DOCUMENT_ROOT}/$0 -d [NC]
RewriteCond %{REQUEST_URI} !^/sites/ [NC]
RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [L]
相关问题