Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache/PHP/.htaccess将文件名路由到filename.PHP_Php_Macos_Apache_.htaccess - Fatal编程技术网

Apache/PHP/.htaccess将文件名路由到filename.PHP

Apache/PHP/.htaccess将文件名路由到filename.PHP,php,macos,apache,.htaccess,Php,Macos,Apache,.htaccess,我试图调试一个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路由 我假设它与.ht

我试图调试一个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>

DocumentRoot“/Users/jim/Sites/sitename.com/public\u html”
ServerName sitename.com
ServerAlias www.sitename.com
选项索引包括以下符号链接符号链接所有者匹配执行CGI多视图
允许超越所有
命令允许,拒绝
通融

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

Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
不确定为什么需要将
Multiviews
设置为“on”,但它是mod_rewrite之前请求的一部分,并会在mod_rewrite之前处理该请求。它接受像
/cart
这样的请求,并决定是否存在与现有资源的模糊匹配。它看到
/cart.php
,并假设这就是您想要的,并在mod_rewrite有机会做任何事情之前提供请求。您可以通过在前面添加一个
-
将其关闭:

Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI -MultiViews
您也可以通过htaccess文件的
选项
指令执行此操作:

Options +FollowSymLinks -MultiViews

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

Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
不确定为什么需要将
Multiviews
设置为“on”,但它是mod_rewrite之前请求的一部分,并会在mod_rewrite之前处理该请求。它接受像
/cart
这样的请求,并决定是否存在与现有资源的模糊匹配。它看到
/cart.php
,并假设这就是您想要的,并在mod_rewrite有机会做任何事情之前提供请求。您可以通过在前面添加一个
-
将其关闭:

Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI -MultiViews
您也可以通过htaccess文件的
选项
指令执行此操作:

Options +FollowSymLinks -MultiViews

你安装了重写引擎了吗?它在其他网站上运行良好,可能与vhosts有关吗?我已经编辑了这个问题,将文件包括在内虚拟主机这与服务器上的几乎相同。因为我仍然认为在你自己的计算机上重写有问题。谢谢,Perry,你是对的,这是在我的计算机上,虚拟主机中的多视图,请参阅Jon LinDid的答案你安装了重写引擎吗?它在其他网站上运行良好,这可能与vhosts有关吗?我已经编辑了这个问题,以包括文件虚拟主机这与服务器上的几乎相同。因为我仍然认为在你自己的计算机上重写是有问题的。谢谢,佩里,你是对的,那是在我的计算机上,虚拟主机中的多视图,见乔恩·林的答案