【问题标题】:How to redirect index.php to another page properly via .htaccess?如何通过 .htaccess 正确地将 index.php 重定向到另一个页面?
【发布时间】:2011-07-09 12:26:41
【问题描述】:

目前我的 htaccess 文件包含此规则,将 website.org/index.php 重定向到 website.org/en/home

RewriteRule index.php /en/home [R=301]

但是,目前还有更深文件夹中的其他index.php 页面重定向!例如website.org/folder/index.php 重定向到 website.org/en/home

我怎样才能让该规则专门应用于根目录,而不是更深的文件夹? 非常感谢。

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect indexing


    【解决方案1】:
    RewriteRule ^index.php /en/home [R=301]
    

    【讨论】:

    • 谢谢!那么,我猜^ 表示它是服务器路径的根目录?
    • 没有。 ^ 表示字符串的开头。您正在尝试匹配相对于 .htaccess 所在文件夹的 url 路径。在这种情况下,它的 index.php。如果是你的前任。 url website.org/folder/index.php, index.php 匹配文件夹/index.php 并做重定向。现在使用 ^index.php 它不匹配文件夹/index.php,因为此 url 以文件夹开头。
    猜你喜欢
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    • 1970-01-01
    • 2014-08-10
    • 2016-12-19
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    相关资源
    最近更新 更多