我有以下重写规则:
RewriteEngine on
RewriteRule ^([^/]+)/?$ parser.php?id=$1 [QSA,L]
问题是,当我尝试通过 www.site.com 访问我的主页时,它也会将其重写为 parser.php,这是为什么?我该如何防止这种情况发生?
答案1
将根免除重写:
RewriteEngine on
# Allow the rewrite to proceed only if the URI does *not* match this pattern
# The pattern used is ^/$ - this will only match the exact string "/" for the root.
RewriteCond %{REQUEST_URI} !^/$
# Your existing rule
RewriteRule ^([^/]+)/?$ parser.php?id=$1 [QSA,L]