2013-07-29 64 views
1

我想调试一个PHP网站,我有一个路由问题,我找不出来。Apache/PHP/.htaccess路由文件名到filename.php

这是一个定制的网站,大部分的请求都通过index.php文件

我遇到的问题是,直播服务器(Linux的/阿帕奇)的路由: http://www.sitename.com/cart通过的index.php作为路由它应该是。

,但我的测试服务器(OSX /阿帕奇)上: http://www.sitename.com/cart去直接http://www.sitename.com/cart.php不通过的index.php

被路由我认为这件事情做的.htaccess文件(如下图),但我可以”弄清楚什么。另外.htaccess文件在两台服务器上都是相同的,所以我不明白为什么它的工作方式不同,任何帮助都非常感谢。

AddType application/x-httpd-php .html 
Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{SERVER_PORT} ^443$ 
RewriteRule ^robots.txt$ robots_ssl.txt 
RewriteCond %{REQUEST_fileNAME} !-f 
RewriteRule ^([^.]+)\.s?html$ /index.php?q=$1 [L,QSA] 
RewriteRule ^([^.]+)\.s?htm$ /index.php?q=$1 [L,QSA] 
RewriteRule ^([^.]+)\.s?xml$ /index.php?q=$1 [L,QSA] 
RewriteRule ^([^.]+)\.s?asp$ /index.php?q=$1 [L,QSA] 
RewriteRule ^([^.]+)\.s?aspx$ /index.php?q=$1 [L,QSA] 
RewriteRule ^robots.txt$ /index.php?q=$1 [L,QSA] 
RewriteRule ^([^.]+)$ /index.php?q=$1 [L,QSA] 
RewriteRule ^admin/.*$ - [PT] 



#php_flag display_errors off 
php_value default_charset ISO-8859-1 
php_flag magic_quotes_gpc on 
php_flag magic_quotes_runtime off 

虚拟主机文件如下:

<VirtualHost *:80> 
    DocumentRoot "/Users/jim/Sites/sitename.com/public_html" 
    ServerName sitename.com 
    ServerAlias www.sitename.com 
     <directory "/Users/jim/Sites/sitename.com/public_html/"> 
      Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews 
      AllowOverride All 
      Order allow,deny 
      Allow from all 
     </directory> 
</VirtualHost> 
+0

是否安装了重写引擎? – Perry

+0

它在其他网站上工作正常,它可能与虚拟主机有关 - 我编辑了问题以包含文件 – jx12345

+1

虚拟主机与服务器上的虚拟主机几乎相同。因为我仍然认为在自己的计算机上重写有问题。 – Perry

回答

1

这是因为这条线在你的虚拟主机配置的情况发生:

Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews 

不知道为什么你需要Multiviews被设置到“开”,但它是mod_negotiation的一部分,并且在 mod_rewrite之前处理请求。它需要像/cart这样的请求,并决定是否存在与现有资源的模糊匹配。它看到/cart.php,并假定这就是你想要的,并在mod_rewrite甚至有机会做任何事情之前提供请求。您可以通过添加在前面的-将其关闭:

Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI -MultiViews 

您也可以通过htaccess文件的Options指令做到这一点:

Options +FollowSymLinks -MultiViews 
+0

的答案完美,谢谢 – jx12345