这是我的重写规则:
###########
# 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]
一切正常(无论如何,任何提高性能或更好的正则表达式的建议都是受欢迎的)但我遇到了一个奇怪的情况,我不明白它是由我的重写规则还是由默认的 Apache 行为产生的。如果我的 URL 以“/”结尾,我可以在不重写的情况下添加任意数量的斜杠。
例如,如果在我的地址栏中插入以下内容:
http://[MY-HOST-NAME]////////////////////////
所有这些斜线都没有被删除。而且我仍然看到我的 index.php 页面。如果我插入以下地址:
http://[MY-HOST-NAME]/members///
所有这些多个斜杠都没有被删除,我可以看到我的成员 index.php 页面。等等...
有人能帮助我吗?非常感谢!