2012-01-27 61 views
0

我有以下设置;一个非常简单的URL重写设置与测试设置Apache URL重写行为不端

// ----- test.php ----- 
<?php 

phpinfo(); 
// ----- test.php ----- 

test.local的配置如下。

<VirtualHost *:80> 
     ServerName test 
     ServerAlias test.* 
     DocumentRoot /var/www/test 
</VirtualHost> 

<Directory "/var/www/test/"> 
     RewriteEngine On 
     RewriteBase/
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteRule .* test.php/$0 [R,NE] 
</Directory> 

现在,如果我提出请求GET http://test.local/my-path-info默认的预期,如果我的路径信息,该作品也添加斜线出现phpinfo()页面。但是如果我在URL中添加一个编码的正斜杠%2F(例如GET http://test.local/my-path-info%2fsomething-else),它会以404 Not found的形式出现。基本上它不会到达php文件。

任何想法为什么会发生这种情况,以及如何解决它?

该设置位于Apache 2.2.13,Linux(CentOS 5.x)上的PHP 5.3.8。

注意:我在这里要做的是将正斜杠添加到其中一个路径信息组件中,这样它就不会被MVC框架中的路由器逻辑解释。如果不对其进行编码,则路由器不能区分作为路径分隔符的斜杠和作为路径组件的一部分的斜杠。

+2

这可以帮助:http://stackoverflow.com/questions/3235219/urlencoded-forward-slash-is-breaking-url – 2012-01-27 15:14:48

+0

难道你想被你指令在你的身体这不成为Apache全球指令? – Skittles 2012-01-29 03:16:18

+0

谢谢@Skittles你是绝对正确的;但同时它是正确的配置,特定于我的设置。 – 2012-01-31 15:59:54

回答

0

因为这并不支持NoDecode作为一个选项,AllowEncodedSlashes Apache的版本,我结束了使用下面的组合。我还必须对请求URI进行url编码。不理想但暂时适合我。

<VirtualHost *:80> 
     ServerName test 
     ServerAlias test.* 
     DocumentRoot /var/www/test 
     AllowEncodedSlashes On 
</VirtualHost> 

<Directory "/var/www/test/"> 
     RewriteEngine On 
     RewriteBase/
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteCond %{REQUEST_FILENAME} !-d 

     # Option B below was the key! 
     RewriteRule .* test.php/$0 [R,NE,B] 
</Directory>