Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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
Php htaccess在windows的xampp中不工作_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php htaccess在windows的xampp中不工作

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

我对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$ /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这样的规则很有趣
将匹配url
http://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根目录(ala
http://example.com
尝试加载
shirts4mike
中的
index.php
)@Sumurai8 shirts4mike在htdocs文件夹中,其他文件在shirts4mike中folder@Sumurai8尝试加载shirts.php文件