0

我有3个文件.htaccess::

RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ cats.php?name=$1

index.php

<?php
echo 'index';

并且cats.php

<?php echo $_GET['name'] . ' < '.$_GET["name"];

我面临的问题是,当我在 site.com 上时,它会将我重定向到cats.php always。但是在我的本地主机上,它在传递参数时才会重定向我,例如: site.com/some-argument

4

1 回答 1

0

这是可能导致问题的行:

RewriteCond %{REQUEST_FILENAME} !-f

这意味着仅当未找到请求的文件名时才执行 RewriteRule 。

在它不工作的本地主机上,您可能在 httpd.conf(或 .htaccess)中有以下设置:

DirectoryIndex index.php

由于上述设置,当您输入时http://site.com,默认情况下index.php会尝试显示,并且由于 Apache 找到了它,因此您的上述 RewriteCond 返回 false 并且您的 RewriteRule 不会触发。

用于测试 RewriteCond 上方的注释并查看是否会改变行为。

于 2013-03-13T09:29:41.297 回答