無法在 XAMPP 中進行 301.htaccess 重定向 (Cannot 301.htaccess redirect in XAMPP)


問題描述

無法在 XAMPP 中進行 301.htaccess 重定向 (Cannot 301.htaccess redirect in XAMPP)

A simple working 301 .htaccess redirect on my live server looks like this:

Options +FollowSymLinks
RewriteEngine on

redirect 301 /test.php /index.php

But I can't make it work my XAMPP installation. I have enabled mod_rewrite.so in the http.conf file and I can't see why it does not redirect.  Have restarted apache but no luck.

‑‑‑‑‑

參考解法

方法 1:

Just to let you know that Apache's redirect directive is from mod_alias module not from more_rewrite module. Check docs here: https://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect

If you want to handle it via mod_rewrite it then use it like this:

RewriteEngine on
RewriteRule ^test\.php$ /index.php [L,NC,R=301]

ALternatively enable mod_alias module to make redirect work.

方法 2:

Got it working by creating a local domain Using Apache Virtual Hosts.  Once the local domain is setup, the redirect code works as it does on the live server:

redirect 301 /test.php /test2.php.php

(by MarkanubhavaMark)

參考文件

  1. Cannot 301.htaccess redirect in XAMPP (CC BY‑SA 3.0/4.0)

#.htaccess #apache #rewrite






相關問題

使用 htaccess 從基本 URL 中刪除變量 (Remove variable from base URL with htaccess)

多個相同的 url htaccess 重定向 (Multiple same url htaccess redirect)

使用 mod_rewrite 更改 URL 中的單詞的問題 (Issue changing a word in a URL using mod_rewrite)

無法在 XAMPP 中進行 301.htaccess 重定向 (Cannot 301.htaccess redirect in XAMPP)

Cách ẩn mọi thứ sau tên trang web của bạn bằng .htaccess (How to hide everything after your webpage name with .htaccess)

htaccess 顯示內部服務器錯誤 (htaccess show internal server error)

mod-rewrite 結合了兩種不同的重寫規則 (mod-rewrite combine two different rewrite rules)

安全的 PHP 文件上傳 (Secure PHP file uploading)

用 .htaccess 重寫基於日期的 URL:s - 解決方案? (Rewriting date-based URL:s with .htaccess - solution?)

htaccess 強制 https 和 www 到非 www,但子域僅 https (htaccess force https & www to non-www, but subdomain only https)

重定向太多。設置 htaccess 以重定向 (too many redirects. setting up htaccess to redirect)

.htaccess https、www 和子域靜默重寫 (.htaccess https, www and subdomain silent rewrite)







留言討論