【发布时间】:2016-09-15 19:12:10
【问题描述】:
我有一个依赖于 htaccess 重写规则的网站,我用这样的序列重写我的 URL:
www.example.com/games/car/play/123
实际上没有以下目录:
- 游戏
- 汽车
- 播放
每天我都会看到我的错误日志显示大量错误行:
File does not exist: /home/example.com/public_html/games
File does not exist: /home/example.com/public_html/car
File does not exist: /home/example.com/public_html/play
我不知道为什么 Apache 将这些假目录视为实际的真实目录?我的 htaccess 中有这几行重写代码:
RewriteEngine On
RewriteBase /
RewriteRule ^games/([a-zA-Z0-9-/]+)/play/(.*)$ details.php?slug=$1&id=$2
现在 Apache 考虑:games/slug/play/id 作为目录,它不仅仅是一个虚假的 URL 序列。另外,当我向下浏览页面时:
www.example.com/games/car 和 www.example.com/games
它已经作为 URL 存在,但不是目录我看到错误日志说:
File does not exist: /home/example.com/public_html/games/car
File does not exist: /home/example.com/public_html/games
我该如何解决这个问题?我已经尝试了所有可行的方法,但我的错误日志中仍然出现大量错误。
非常感谢(抱歉我的英语不好)。
【问题讨论】:
-
在您的 access.log 中,您是否看到对
/games或/play等的请求? -
"我不知道为什么 Apache 将这些假目录视为真正的真实目录?" - 因为您的
RewriteRulepattern 与这些 URL 中的任何一个都不匹配,并且您或其他人正在链接到这些 URL。如果模式不匹配,那么 Apache 就别无选择,只能尝试请求/games或/car等,这自然会触发 404 Not Found。这些其他 URL 是否应该有效?如果是这样,它们应该映射到什么? -
@anubhava ,是的,我看到 /games 或 /play 的日志错误太多。这些 URL 是有效的,并映射到页面的类别 slug: category_details.php ,但对于 /play 它不会映射到任何东西。
-
这意味着你收到了一些无效的http请求,这与重写规则无关。
标签: .htaccess logging url-rewriting rules