1

我正在尝试调试一个 php 站点,但遇到了一个我无法弄清楚的路由问题。

这是一个自定义构建的站点,大多数请求都通过 index.php 路由

我遇到的问题是在实时服务器(Linux / Apache)上: http://www.sitename.com/cart应该是通过 index.php 路由的。

但在我的测试服务器(osx / apache)上: 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>
4

1 回答 1

1

发生这种情况是因为您的 vhost 配置中的这一行:

Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

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

Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI -MultiViews

您也可以通过 htaccess 文件的Options指令执行此操作:

Options +FollowSymLinks -MultiViews
于 2013-07-29T17:12:47.537 回答