这是我的 htaccess: 选项+FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/pages
RewriteRule ^(.+)/$ /$1 [NC]
RewriteRule ^$ /pages/index.php [NC]
RewriteRule ^([a-z]+)\?([^/]+)$ /pages/$1.php?$2 [NC]
RewriteRule ^([a-z]+)/([^/]+)$ /pages/$1.php?q=$2 [NC]
RewriteRule ^([a-z]+)$ /pages/$1.php [NC]
ErrorDocument 404 /pages/404.php
应该做的事情很简单:
- 删除网址尾部斜杠
- 将 example.com/tomato 定向到 example.com/pages/tomato.php
- 直接 example.com/tomato?c=red&size=big 到 example.com/pages/tomato.php?c=red&size=big
- 将 example.com/tomato/red 定向到 example.com/pages/tomato.php?q=r
但这就是问题所在:for/pages/tomato.php 的任何 URL 都与 .htaccess 的第 7 行匹配,这将产生无限循环。这就是为什么我为/pages 添加了一个异常(exception),但它似乎被忽略了 - 我仍然收到 500 Internal Server Error 并显示以下日志消息:
mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.
这可能与我使用虚拟主机运行此程序有关吗?如果是这样,应该采取什么措施来解决它?
最佳答案
RewriteCond 仅适用于下一个 RewriteRule,因此您必须为每个规则复制该条件。
关于apache - .htaccess 似乎忽略了 RewriteCond,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3277365/