問題描述
無法在 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