簡體   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