Apache 重写适用于 FreeBSD,但不适用于 CentOS

Apache 重写适用于 FreeBSD,但不适用于 CentOS

我有 5 台运行 FreeBSD 9.2 的生产服务器,但我们计划过渡到 CentOS。因此,我尝试设置一些虚拟机来模拟使用 CentOS 6.6 的生产服务器环境。我已经设置好了一切,运行良好,节省了一条重写规则。

<Directory /var/www/html/www/trunk/amapi>
  RewriteEngine on
  RewriteRule  ^$ public/    [L]
  RewriteRule  (.*) public/$1 [L]
</Directory>
<Directory /var/www/html/www/trunk/amapi/public>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</Directory>
<Directory /var/www/html/www/trunk>
  RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*start\.php
  RewriteRule ^start.php/?(.*)$ $1 [R=301,L]

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ start.php/$1?%{QUERY_STRING} [L]
</Directory>

前两个重写规则适用于使用 Phalcon 的后端 API,它们在两种环境中都能完美运行。第三个重写规则是一个捕获所有请求的规则,它将所有与实际文件不匹配的请求重定向到 start.php,后者会尝试将它们与 Phalcon 模块匹配,然后如果没有匹配的路由,则转到 404 页面。

由于某种原因,它在运行 Apache 2.2.27 的 FreeBSD 下可以工作,但在目前运行 Apache 2.2.15 的 CentOS 下却不行。这是一个非常简单的重写规则,应该可以在任何版本的 Apache 下正常工作,但当我尝试访问该文件时,apache 总是抛出 404。我是不是漏掉了什么?显然,显示的代码中缺少 SSL 配置和特定选项,但这些是请求在 ssl.conf 中出现的顺序。

提前致谢

更新:Apache Rewrite 日志为:

10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (2) init rewrite engine with requested uri /letters/custom/test
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (3) applying pattern '^/attc2/(.*)$' to uri '/letters/custom/test'
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (3) applying pattern '^/forms/(.*)$' to uri '/letters/custom/test'
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (3) applying pattern '^/grafx/(.*)$' to uri '/letters/custom/test'
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (3) applying pattern '^/xport/(.*)$' to uri '/letters/custom/test'
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (3) applying pattern '.*' to uri '/letters/custom/test'
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (4) RewriteCond: input='' pattern='!.*mydomain.com/.*$' [NC] => matched
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (4) RewriteCond: input='/letters/custom/test' pattern='\\.(jpg|gif|png)$' => not-matched
10.1.1.135 - - [24/Feb/2015:17:39:17 --0500] [trunk.mydomain.com/sid#7f18f3072f98][rid#7f18f36099b8/initial] (1) pass through /letters/custom/test

答案1

我想知道问题是否只是一个未转义的点。尝试替换此行:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*start\.php

和:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\.*start\.php

相关内容