【问题标题】:htaccess redirecting index, no file extensionhtaccess 重定向索引,没有文件扩展名
【发布时间】:2014-12-17 08:32:06
【问题描述】:

我刚碰到这个。我正在运行一个 wordpress 网站,我想将这个 www.dentistcostamesadds.com/index 重定向到 www.dentistcostamesadds.com。我下面的代码不起作用。

# Permanent URL redirects
RewriteEngine On
RewriteBase /
Redirect 301 /index http://www.dentistcostamesadds.com

如下所示,只有没有 extension/index 不起作用。为什么?

Redirect 301 /index.php http://www.dentistcostamesadds.com WORKS
Redirect 301 /index.html http://www.dentistcostamesadds.com WORKS
Redirect 301 /index.aspx http://www.dentistcostamesadds.com WORKS
Redirect 301 /home http://www.dentistcostamesadds.com WORKS
Redirect 301 /home.html http://www.dentistcostamesadds.com WORKS
Redirect 301 /index http://www.dentistcostamesadds.com DOESN'T WORK

【问题讨论】:

    标签: php apache .htaccess http-status-code-301


    【解决方案1】:

    这是因为 Redirect 指令自动将 URI 的其余部分附加到目标。所以如果你只有:

    Redirect 301 /abc http://domain.com/xyz
    

    这意味着对/abc1234 的请求将被重定向到http://domain.com/xyz1234,而/abc/foo/bar 将被重定向到http://domain.com/xyz/foo/bar。因此,如果您想重定向所有这些内容,可以尝试使用正则表达式:

    RedirectMatch 301 ^(index|home)(\.php|\.html|\.aspx)?$ http://www.dentistcostamesadds.com
    

    【讨论】:

      【解决方案2】:

      以下方法可以解决问题:

      RewriteEngine On
      RewriteRule ^index?$                               /
      

      这表示将请求重定向到 www.(...)/index 到 www.(...)

      其中 www.(...) 是域。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-31
        • 1970-01-01
        • 2012-12-20
        • 2023-03-14
        • 2016-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多