【问题标题】:Adding A Trailing Backslash Cause A Error 500添加尾部反斜杠会导致错误 500
【发布时间】:2016-08-05 17:19:18
【问题描述】:

在 URL 末尾添加尾部反斜杠会导致错误 500,即 /forum/。当输入 /forum 时,/forum.php 会按预期加载到浏览器上。检查错误日志文件后,它指出

请求超出了 10 个内部重定向的限制,因为可能 配置错误。使用“LimitInternalRecursion”来增加 必要时限制。使用“LogLevel debug”获取回溯。

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(admin|user)($|/) - [L]


#RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f

RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^([A-Za-z0-9-_]+)$ /index.php?view=$1 [L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?view=$1&page=$2 [L]

如果我添加反斜杠“?/”,/forum 将加载索引页面,/forum/ 将加载 /forum.php

RewriteRule ^(.*)?/$ $1.php [L]

我哪里做错了?提前谢谢你。

【问题讨论】:

    标签: php apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^(.*)$ $1.php [L]
    

    这个RewriteCond 条件应该防止在请求的文件存在的情况下重写。在您的情况下,/forum 将被重写为 /forum.php,然后将重写的请求返回给 URL 解析引擎,该引擎将发现 /forum.php 存在并且不会再次执行此规则。

    当您请求/forum/ 时,它会被重写为不存在的/forum/.php,因此它会被重写为/forum/.php.php 等。如果您启用了重写logging,您可以在错误日志中看到这一点

    快速解决办法是用这个去掉尾斜线(把它放在RewriteBase /下面:

    RewriteRule ^(.*)/$ /$1 [NC,L]
    

    【讨论】:

      猜你喜欢
      • 2012-01-06
      • 1970-01-01
      • 2018-11-18
      • 2012-08-03
      • 2012-09-25
      • 2012-07-06
      • 1970-01-01
      • 2017-08-09
      • 2015-01-16
      相关资源
      最近更新 更多