如何修复apache2日志中的“找不到文件”错误

时间:2013-05-08 05:42:54

标签: apache mod-rewrite file-not-found

我正在用PHP构建MVC框架。我正在使用像这样的分段URL:

http://mydomain.com/controller/method/param1/param2

我在Apache .htaccess中使用以下重写规则:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&method=$2&param1=$3&param2=$4 [NC,L]

URL工作正常,并且正在调用正确的控制器和方法。但是,我在apache2 error.log中遇到了很多错误。无论何时我访问具有两个或更多段的URL,我都会收到“找不到文件”错误。浏览器中没有404。

为了澄清,以下URL不会导致Apache日志中的错误。

http://dev.bonesphp.com/about

但是,以下网址会导致错误:

http://dev.bonesphp.com/about/test/pre>

File does not exist: /var/www/vhosts/dev.bonesphp.com/about

My php.ini error settings are set to E_ALL / STRICT

Does anyone know how to fix this?

Thanks in advance!

UPDATE: 5/12/2013

I enabled the rewrite log in Apache. This is what the rewrite log says when I try to access the above URL:

127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] add path info postfix: /var/www/vhosts/dev.bonesphp.com/about -> /var/www/vhosts/dev.bonesphp.com/about/test 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/about/test -> about/test 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$' to uri 'about/test' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (2) [perdir /var/www/vhosts/dev.bonesphp.com/] rewrite 'about/test' -> 'index.php?controller=about&method=test¶m1=¶m2=' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (3) split uri=index.php?controller=about&method=test¶m1=¶m2= -> uri=index.php, args=controller=about&method=test¶m1=¶m2= 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] add per-dir prefix: index.php -> /var/www/vhosts/dev.bonesphp.com/index.php 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (2) [perdir /var/www/vhosts/dev.bonesphp.com/] strip document_root prefix: /var/www/vhosts/dev.bonesphp.com/index.php -> /index.php 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747170a0/initial] (1) [perdir /var/www/vhosts/dev.bonesphp.com/] internal redirect with /index.php [INTERNAL REDIRECT] 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a3508/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/index.php -> index.php 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a3508/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$' to uri 'index.php' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a3508/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/index.php -> index.php 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a3508/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '(^|/)\.' to uri 'index.php' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a3508/initial/redir#1] (1) [perdir /var/www/vhosts/dev.bonesphp.com/] pass through /var/www/vhosts/dev.bonesphp.com/index.php 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] add path info postfix: /var/www/vhosts/dev.bonesphp.com/about -> /var/www/vhosts/dev.bonesphp.com/about/favicon.ico 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/about/favicon.ico -> about/favicon.ico 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$' to uri 'about/favicon.ico' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] add path info postfix: /var/www/vhosts/dev.bonesphp.com/about -> /var/www/vhosts/dev.bonesphp.com/about/favicon.ico 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/about/favicon.ico -> about/favicon.ico 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '(^|/)\.' to uri 'about/favicon.ico' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b747130a0/initial] (1) [perdir /var/www/vhosts/dev.bonesphp.com/] pass through /var/www/vhosts/dev.bonesphp.com/about 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a1290/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/404.html -> 404.html 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a1290/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?([a-zA-Z0-9]*)?/?$' to uri '404.html' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a1290/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] strip per-dir prefix: /var/www/vhosts/dev.bonesphp.com/404.html -> 404.html 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a1290/initial/redir#1] (3) [perdir /var/www/vhosts/dev.bonesphp.com/] applying pattern '(^|/)\.' to uri '404.html' 127.0.0.1 - - [12/May/2013:17:52:35 --0400] [dev.bonesphp.com/sid#7f0b748dc0a8][rid#7f0b6e4a1290/initial/redir#1] (1) [perdir /var/www/vhosts/dev.bonesphp.com/] pass through /var/www/vhosts/dev.bonesphp.com/404.html

1 个答案:

答案 0 :(得分:0)

我终于解决了这个问题! “文件不存在”错误是由浏览器对favicon.ico的请求引起的!

当网址只有一个网段(例如http://dev.bonesphp.com / about )时,浏览器会从网站的根目录中请求图标,这正是我的图标所在的位置。但是,如果网址包含两个细分,例如http://dev.bonesphp.com / about / test ,则浏览器会从子目录中请求它。在上述URL的情况下,它在http://dev.bonesphp.com/about中查找favicon。这导致404,因为没有名为'about'的目录('/ about'映射到名为About.php的控制器文件)。

在Google上搜索后,我发现了一条Apache重写规则,该规则适用于任何目录中请求的favicon:

http://perishablepress.com/redirect-all-requests-for-a-nonexistent-file-to-the-actual-file/

什么是PIA!我很高兴这已经结束了!