【问题标题】:301 Redirect a folder to a single page301 将文件夹重定向到单个页面
【发布时间】:2014-11-27 07:30:19
【问题描述】:

我的网站上有一个文件夹已被取代,我想将访问此文件夹中任何文件的尝试重定向到当前主页。

我在这里阅读了很多问题,但似乎没有一个完全做到这一点。

我在 .htaccess 中尝试了各种方法,但它似乎总是将文件名附加到重定向地址。

redirect 301 old/$ www.example.com/index.html
redirect 301 old/ www.example.com/index.html
redirect 301 ^old/ www.example.com/index.html

我看到过各种提到 RewriteRule。我需要使用它吗?

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    您可以在/old/.htaccess 文件中使用此代码:

    RewriteEngine On
    
    RewriteRule ^ http://www.example.com/index.html [L]
    

    或从根 .htaccess 使用:

    RewriteEngine On
    
    RewriteRule ^old(/.*)?$ http://www.example.com/index.html [L,NC]
    

    【讨论】:

    • 忽略以上 - 我没有意识到编辑 cmets 有时间限制。我让它工作,但前提是我输入完整的 URL,而不仅仅是 /index.html ??
    • 不客气,很高兴它成功了。 (答案已更新)
    猜你喜欢
    • 2015-09-24
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    相关资源
    最近更新 更多