[英]XAMPP .htaccess mod_rewrite not working
我正在運行XAMPP for Windows 5.6.11。 我有以下PHP文件:
C:\xampp\htdocs\www.johndoe.com\index.php
我正在訪問
http://localhost/www.johndoe.com/
事實上,我需要訪問以下頁面:
http://localhost/www.johndoe.com/?value=about
作為以下兩種之一:
http://localhost/www.johndoe.com/about/
http://localhost/www.johndoe.com/about
所以我的.htaccess文件中有以下內容:
RewriteEngine on
RewriteRule ^www\.johndoe\.com/about/?$ www.johndoe.com/?value=about
但是,這不起作用,因為訪問以前的站點給了我401(未找到)。
這是我在C:\\xampp\\apache\\conf\\httpd.conf
:
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
我該怎么做才能解析我的.htaccess
文件並執行我之后的替換?
我嘗試將以下內容放在C:\\xampp\\apache\\conf\\httpd.conf
:
<Directory />
AllowOverride all
Require all allowed
</Directory>
但是沒有運氣。 我甚至嘗試將.htaccess
文件更改為以下內容:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /www.johndoe.com/
RewriteRule ^about/?$ ?value=about
但我仍然收到404未找到錯誤消息。
事實證明,使用默認的XAMPP配置,不需要C:\\xampp\\apache\\conf\\httpd.conf
,因此無需重新啟動Apache,因為我們只是對C:\\xampp\\htdocs\\www.johndoe.com\\.htaccess
進行了更改C:\\xampp\\htdocs\\www.johndoe.com\\.htaccess
。 正如RewriteBase上的這篇文章解釋的那樣,我們不需要RewriteBase
因為我們不會在.htaccess
規則的目標鏈接中使用絕對路徑。 由於這些目標規則中的相對鏈接將與我們提供的目錄相關,因此我們需要從規則中刪除www.johndoe.com
目錄,如下所示:
.htaccess
放在``C:\\ xampp \\ htdocs \\ www.johndoe.com`中。 將以下重新包含在其中:
RewriteEngine on RewriteRule ^about/?$ index.php?value=about
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.