【问题标题】:.htaccess redirect directory to a single page.htaccess 将目录重定向到单个页面
【发布时间】:2012-05-25 10:27:58
【问题描述】:

我想将 所有 页面从 .com/blog 目录重定向到 .com/error 目录。

我搜索了网络,发现了很多不同的方法,但我希望它重定向到一个单个页面。

我尝试过的所有东西都重定向到相同的文件名,但在不同的目录中。例如,.com/blog/index.nonexisting 重定向到 .com/error/index.nonexisting

我希望第一个目录中的所有文件都重定向到某个文件,所以如果您转到.com/blog/whatever.php,它将转到.com/error/index.php,如果您转到.com/blog/random.xml,您将被重定向到@987654328 @。

有什么办法吗?

【问题讨论】:

    标签: .htaccess redirect url-rewriting web


    【解决方案1】:

    试着把它放在你的 .htaccess 中:

    RewriteEngine on
    RewriteRule ^blog/(.+) error/index.php [L,R]
    

    如果您想要 301 重定向,请将 R 替换为 R=301,如果您不想要外部重定向,请完全删除 R

    【讨论】:

    • 朋友我想 301 将我的整个博客文件夹重定向到主页 url。当有人指向我的博客链接时,它会自动重定向到主页。使用 htaccess。谢谢。
    • 谢谢!!你节省了我很多时间
    【解决方案2】:

    在 wordpress 中,我将它用于多站点上的 subdmoain。

    所以“subdomain.domain.org/wp_super_faq/AnyAndAllTextAtAll”将重定向到“subdomain.domain.org/faqs”

    RewriteCond %{HTTP_HOST} ^subdomain\.domain\.org [NC]
    RewriteRule ^wp_super_faq.*$ https://subdomain\.domain\.org/faqs/ [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-19
      • 2016-07-20
      • 2014-08-10
      • 2017-07-27
      • 1970-01-01
      相关资源
      最近更新 更多