0

I am using apache's mod rewrite to make "pretty urls", here is an example of a rule:

RewriteRule ^articles/(.+?)\.([0-9]+)/page\=([0-9]+)?$ /index.php?module=articles_full&aid=$2&title=$1&page=$3 [N,NC,QSA]

Problem is my error log fills up with stuff like this:

[Fri Feb 01 20:36:11 2013] [error] [client 94.246.88.189] File does not exist: /home/gamingon/public_html/articles
[Fri Feb 01 20:35:55 2013] [error] [client 66.249.73.195] File does not exist: /home/gamingon/public_html/articles
[Fri Feb 01 20:34:39 2013] [error] [client 66.249.73.195] File does not exist: /home/gamingon/public_html/articles

What would be the best way to stop the errors? It seems to work okay though but still i don't think the error logs are supposed to fill with that?

4

1 回答 1

0

添加一个 RewriteCond ,仅当文件不存在时才会启动 RewriteRule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^articles/(.+?)\.([0-9]+)/page\=([0-9]+)?$ /index.php?module=articles_full&aid=$2&title=$1&page=$3 [N,NC,QSA]

编辑:

再次查看您的重写规则,这是一个非常具体的正则表达式,仅当 uri 采用格式时才会匹配

  • 文本“文章”
  • 一个或多个任意字符
  • 一个点
  • 一位或多位数字
  • 文本“/pages=”
  • 一位或多位数字

因此,它将匹配如下 URL:

但不在 URL 上,例如:

如果您看到 404,很可能人们正在尝试访问第二种形式的 URL。可能是您的网站有一些未正确创建的链接,请检查日志以查看是否可以找到任何引用者来帮助追踪问题。

我测试了你的规则,当我给它一个格式正确的 URL 时,它对我来说很好。

于 2013-02-04T08:17:22.930 回答