我正在用 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¶m1=$3¶m2=$4 [NC,L]
URL 工作正常,并且正在调用正确的控制器和方法。但是,我在 apache2 error.log 中遇到了很多错误。每当我访问包含两个或更多段的 URL 时,我都会收到“找不到文件”错误。浏览器中没有发生 404。
澄清一下,以下 URL 不会导致 Apache 日志中出现错误。
http://dev.bonesphp.com/about
但是,以下 URL 会导致错误:
http://dev.bonesphp.com/about/test/pre >文件不存在:/var/www/vhosts/dev.bonesphp.com/about
我的 php.ini 错误设置设置为 E_ALL / STRICT
有谁知道如何解决这一问题?
提前致谢!
更新:2013 年 5 月 12 日
我在 Apache 中启用了重写日志。这是我尝试访问上述 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/] 添加路径信息后缀:/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/] 去除每个目录前缀:/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/] 应用模式 '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9] *)?/?([a-zA-Z0-9]*)?/?$' 到 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/] 重写 '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) 拆分 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/] 添加每个目录前缀: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/] 去除 document_root 前缀:/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/] 内部重定向与 /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/] 去除每个目录前缀:/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/] 应用模式 '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA- Z0-9]*)?/?([a-zA-Z0-9]*)?/?$' 到 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/] 去除每个目录前缀:/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/] 应用模式 '(^|/)\.' 到 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/] 通过 /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/] 添加路径信息后缀:/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/] 去除每个目录前缀:/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/] 应用模式 '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9] *)?/?([a-zA-Z0-9]*)?/?$' 到 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/] 添加路径信息后缀:/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/] 去除每个目录前缀:/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/] 应用模式 '(^|/)\.' 到 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/] 通过 /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/] 去除每个目录前缀:/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/] 应用模式 '^([a-zA-Z\-_]*)/?([a-zA-Z]*)?/?([a-zA- Z0-9]*)?/?([a-zA-Z0-9]*)?/?$' 到 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/] 去除每个目录前缀:/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/] 应用模式 '(^|/)\.' 到 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/] 通过 /var/www/vhosts/dev.bonesphp.com/404.html