这是我的重写规则:
########### # Rewrite # ########### # Settings RewriteEngine On RewriteBase / # Cache Busting RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} "^(.+).d+.(css|js)$" [NC] RewriteRule "^.*$" "/%1.%2" [L] # No Index RewriteCond %{THE_REQUEST} " /.*index.php.* " [NC] RewriteRule "^(.*)index..+$" "/$1" [L,NC,R=301] # No Question Mark RewriteCond %{THE_REQUEST} " /[^?]*? " RewriteRule "^(.*)$" "/$1?" [L,R=301] # WWW # RewriteCond %{HTTP_HOST} !"^(?:static|www).(.+)$" [NC] # RewriteCond %{HTTPS}s "^on(s)|" # RewriteRule "^(.*)$" http%2://www.%1/$1 [L,R=301]
一切工作正常(任何提高性能或更好的正则expression式的build议是受欢迎的,无论如何),但我遇到了一个奇怪的情况,我不明白,如果它是由我的重写规则或默认的Apache行为产生的。 如果我的URL以“/”结尾,那么我可以在不重写的情况下添加尽可能多的斜线。
例如,如果在我的地址栏中插入以下内容:
HTTP:// [MY-HOST-NAME] ////////////////////////////
将Apache .htaccess转换为Nginx
多个停放域的redirect不适用于文件名
如何在.htaccessredirect后通过ajax请求保留POST数据?
mod_rewrite:添加尾部斜杠?
使用.htaccess将查询string附加到所有URL
所有这些斜杠都没有被删除。 而我仍然看到我的index.php页面。 如果我插入以下地址:
HTTP:// [MY-HOST-NAME] /构件///
所有这些多个斜杠不会被删除,我可以看到我的成员index.php页面。 等等…
有人能帮助我吗? 非常感谢!
用mod_rewrite重写PHP中的URL
子域名在不改变地址栏中的URL的情况下使用htaccessredirect
如何对子目录进行dynamic修改
index.php查询参数的.htaccess中的URL RewriteRule
如何停止inheritance父级的htaccess规则的子目录
RewriteCond %{THE_REQUEST} // RewriteRule .* $0 [R]
RewriteEngine on RewriteBase / #existing rule #remove the www. RewriteCond %{HTTP_HOST} ^www.website.co.uk$ [NC] RewriteRule ^(.*)$ http://local.website.co.uk/$1 [R=301,L] #new Rule #if its not a directory RewriteCond %{REQUEST_FILENAME} !-d #and it has a trailing slash then redirect to URL without slash RewriteRule ^(.+)/$ /$1 [L,R=301] # rest of your existing rules go here
Gerbens对于.htaccess的回答很好,但对于全局配置却没有那么多。 这个在发送重定向之前删除所有的斜杠。
# if match set environment variable and start over RewriteRule ^(.*?)//+(.*)$ $1/$2 [E=REDIR:1,N] # if done at least one. redirect with 301 RewriteCond %{ENV:REDIR} 1 RewriteRule ^/(.*) /$1 [R=301,L]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。