Php htaccess在windows的xampp中不工作
我对httpd.conf文件进行了如下编辑:Php htaccess在windows的xampp中不工作,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我对httpd.conf文件进行了如下编辑: 更改为AllowOverride All 这是我的.htaccess文件: RewriteEngine On RewriteRule ^shirts/$ /shirts/shirts.php RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1 RewriteRule ^receipt.php$ /receipt/ [R=301] RewriteRule ^contact.php$ /con
- 更改为AllowOverride All
RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1
RewriteRule ^receipt.php$ /receipt/ [R=301]
RewriteRule ^contact.php$ /contact/ [R=301]
RewriteRule ^shirts.php$ /shirts/ [R=301]
RewriteRule ^(shirts/[0-9]+)$ /$1/ [R=301]
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^shirt.php$ /shirts/%1/? [R=301]
文件夹结构如下所示:
衬衫4Mike+联系方式
+css
+img
+公司
+收据
+衬衫
|_shirt.php
|_shirts.php
-.htaccess
-favicon.ico
-index.php 我尝试了很多次,但当我在主页中单击衬衫时,仍然显示索引文件不存在。
我认为xampp确实忽略了.htaccess文件。
如果是这样,我应该如何修复?问题似乎是您试图重写子目录中的url,但它链接到http根目录。您需要在子目录中有
.htaccess
文件。您会注意到,像RewriteRule^test$/testing这样的规则很有趣
将匹配urlhttp://example.com/shirts4mike/test
,但是在http根目录中重写到文件测试很有趣。因此,我们需要修复规则的重写部分
修复程序使用的是相对url,而不是绝对url。这可以通过删除前缀/
来完成。对于重定向,使用子目录定义RewriteBase
。我也会在每个规则中添加[L]
标志。您的.htaccess
应该如下所示:
RewriteEngine On
RewriteBase /shirts4mike/
RewriteRule ^shirts/$ shirts/shirts.php [L]
RewriteRule ^shirts/([0-9]+)/$ shirts/shirt.php?id=$1 [L]
RewriteRule ^receipt.php$ receipt/ [R=301,L]
RewriteRule ^contact.php$ contact/ [R=301,L]
RewriteRule ^shirts.php$ shirts/ [R=301,L]
RewriteRule ^(shirts/[0-9]+)$ $1/ [R=301,L]
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^shirt.php$ shirts/%1/? [R=301,L]
作为旁注:我鼓励您在测试重写规则时不要使用[R=301]
。一些浏览器缓存永久重定向以提高性能。如果您的规则按照您期望的方式工作,这是可以的,但是如果不是这样,进一步的测试可能会链接到您的旧页面。这意味着当您更改.htaccess
时,您必须清除缓存以查看当前情况。您是否已在httpd.conf
中包含加载模块重写\u模块/module\u重写。因此,您是否已重新启动服务?您需要停止并启动apache,才能使httpd.conf
中的任何更改生效。@Sumurai8您好,我已经包含了它。我发现如果我把这些文件放在shirts4mike文件夹之外,这意味着这些文件在根文件夹中。它工作,如果不工作,就不工作了…是你的http根目录(alahttp://example.com
尝试加载shirts4mike
中的index.php
)@Sumurai8 shirts4mike在htdocs文件夹中,其他文件在shirts4mike中folder@Sumurai8尝试加载shirts.php文件