Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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 重写规则无效_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Apache 重写规则无效

Apache 重写规则无效,apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,我在Apache虚拟主机配置httpd-vhosts.conf中使用了一些重写规则,在那里可以正常工作。因为我想移动到托管服务器,所以我必须使用.htaccess文件,因为我没有访问apache配置文件的权限 我在当地试过,但不知怎么的,我一点也没用。 在本地,我使用XAMPP1.8.3(Apache 2.4.10)。我将.htaccess文件放在虚拟主机的根目录中,并使用此行进行测试 Options +FollowSymLinks RewriteEngine On RewriteBase /

我在Apache虚拟主机配置httpd-vhosts.conf中使用了一些重写规则,在那里可以正常工作。因为我想移动到托管服务器,所以我必须使用.htaccess文件,因为我没有访问apache配置文件的权限

我在当地试过,但不知怎么的,我一点也没用。 在本地,我使用XAMPP1.8.3(Apache 2.4.10)。我将.htaccess文件放在虚拟主机的根目录中,并使用此行进行测试

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule /testrule /about/about.php [L]
调用
localhost/testrule
当我把它放在
httpd vhosts.conf
中时,它可以正常工作。
mod\u rewrite已启用,我已在目录部分中设置了
AllowOverride All

您可以在此处快速检查htaccess重写规则:
或者在这里:

只要去掉重写规则中的前导斜杠,就完成了

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule testrule /about/about.php [L]
这清楚地提到

在VirtualHost上下文中,模式最初将与 URL中位于主机名和端口之后、查询之前的部分 字符串(例如“/app1/index.html”)

在目录和htaccess上下文中,模式最初是 删除前缀后,与文件系统路径匹配 将服务器引导到当前重写规则(例如“app1/index.html”或 “index.html”,具体取决于指令的定义位置)

因此,在虚拟主机上下文中,匹配从
/testrule/…


.htaccess
上下文中,它与
testrule/…

匹配。感谢您提供这些信息,现在我了解了必须删除前导代码的背景slash@RahilWazir我一直想象它会是这样,但从来没有费心去寻找它。谢谢你的信息。