2013-07-29 56 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