如何使用 htaccess 将 index.php 请求重定向到 /home


How to redirect requests for index.php to /home with htaccess

我目前正在使用此方法

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.mysite.com/home$1 [R=301,L]

这有效,但是有没有办法在不手动输入的情况下获取Web根目录。以便自动替换"http://www.mysite.com"部分。只是为了让我可以在本地服务器和生产中使用它而无需进行更改。

是的,当然你可以使用:

RewriteCond %{THE_REQUEST} /index'.php [NC
RewriteRule ^(.*)index'.php$ /home$1 [R=301,L,NC]

仅当您的规则重定向到外部 URL 时,目标 URI 才需要具有 http:// U的完整站点地址,但在这种情况下,您不需要。