繁体   English   中英

htaccess在Windows的xampp中不起作用

[英]htaccess is not working in xampp in windows

我已经编辑了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]  

文件夹结构是这样的:

衬衫
+联系
+ CSS
+ img
+公司
+收据
+衬衫
| _ shirt.php
| _ shirts.php
-.htaccess
-favicon.ico
-index.php

我已经尝试了很多次,但是当我单击主页中的衬衫时,它仍然显示索引文件没有退出。
我认为xampp确实会忽略.htaccess文件。
如果是这样,我该如何解决?

问题似乎是您尝试在子目录中重写url,但是它链接到http-root目录。 您需要在子目录中具有.htaccess文件。 你会发现,就像一个规则RewriteRule ^test$ /testing-is-fun将匹配的URL http://example.com/shirts4mike/test ,但改写到一个文件testing-is-fun在你的http根。 因此,我们需要修复规则的重写部分。

解决方法是使用相对网址,而不是绝对网址。 这可以通过删除前缀/来完成。 对于重定向,请在其中定义带有子目录的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 ,必须清除缓存以查看当前情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM