apache重定向 - 条件不正确匹配

时间:2013-01-14 19:30:15

标签: apache mod-rewrite

我在Apache(2.2)config

的virtualhost部分中有以下简单的重写语句和条件
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^([^\.]{2,})$ /bootstrap.php?url=$1 

如果文件存在,所有请求都很好地重定向到bootstrap.php,execpt。这很好。但是,如果存在目录,我希望Apache为该目录运行DirectoryIndex,或显示目录的内容(我选择的任何设置),但Apache也将请求定向到bootstrap.php。似乎第一个rewriteCond在某种程度上是不正确的。我究竟做错了什么?

在进行调试并尝试加载“localhost / img”(存在)时,我得到以下输出

127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (2) init rewrite engine with requested uri /img/
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (3) applying pattern '^([^\.]{2,})$' to uri '/img/'
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (4) RewriteCond: input='/img/' pattern='!-d' => matched
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (4) RewriteCond: input='/img/' pattern='!-f' => matched
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (2) rewrite '/img/' -> '/bootstrap.php?url=/img/'
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (3) split uri=/bootstrap.php?url=/img/ -> uri=/bootstrap.php, args=url=/img/
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (2) local path result: /bootstrap.php
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (2) prefixed with document_root to C:/webroot/zippyshoot/bootstrap.php
127.0.0.1 - - [14/Jan/2013:20:18:14 +0100] [localhost/sid#4cd5a8][rid#14442c0/initial] (1) go-ahead with C:/webroot/zippyshoot/bootstrap.php [OK]

加载localhost / img / logo.png时工作正常。然后输出调试日志

127.0.0.1 - - [14/Jan/2013:20:27:56 +0100] [localhost/sid#4cd5a8][rid#237d978/initial] (2) init rewrite engine with requested uri /img/logo.png
127.0.0.1 - - [14/Jan/2013:20:27:56 +0100] [localhost/sid#4cd5a8][rid#237d978/initial] (3) applying pattern '^([^\.]{2,})$' to uri '/img/logo.png'
127.0.0.1 - - [14/Jan/2013:20:27:56 +0100] [localhost/sid#4cd5a8][rid#237d978/initial] (1) pass through /img/logo.png

我做错了什么?

1 个答案:

答案 0 :(得分:1)

我在这篇文章中找到了问题的答案 http://amandine.aupetit.info/135/apache2-mod_rewrite/

从Apache 2.2开始,rewriteCond已更改。现在正在编写它们的正确方法

     RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
     RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
     RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-l