【问题标题】:How to redirect requests for index.php to /home with htaccess如何使用 htaccess 将 index.php 的请求重定向到 /home
【发布时间】:2013-11-11 10:56:31
【问题描述】:

我目前正在使用这种方法

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

这行得通,但是有什么方法可以在不手动输入的情况下获取 Web 根目录。以便自动替换“http://www.mysite.com”部分。只是这样我就可以在我的本地服务器以及生产中使用它而无需进行更改。

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    是的,你可以使用:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-13
      • 2015-04-10
      • 1970-01-01
      • 2016-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多