【问题标题】:htaccess redirect without the pathhtaccess 重定向没有路径
【发布时间】:2015-07-21 20:26:05
【问题描述】:

我有以下 htaccess 规则:

Redirect 301 / http://www.example.co.uk/blog/

http://blog.example.co.uk/ 的旧博客上,应该将所有网址从这个旧博客重定向到新博客。

但是,如果我在路径中有任何东西:例如http://blog.example.co.uk/2015/test-post 然后重定向到http://www.example.co.uk/blog/2015/test-post

我如何使它不保留路径而只是重定向到域。

【问题讨论】:

    标签: regex apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您需要为此使用RedirectMatch

    RedirectMatch 301 ^ http://www.example.co.uk/blog/
    

    请务必在新浏览器中进行测试。

    或者,如果您还想删除任何现有的查询字符串,请使用mod_rewrite

    RewriteEngine On
    RewriteRule ^ http://www.example.co.uk/blog/? [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2020-10-01
      • 2011-05-10
      • 1970-01-01
      • 2011-11-08
      • 1970-01-01
      • 2014-06-22
      • 1970-01-01
      • 1970-01-01
      • 2021-02-27
      相关资源
      最近更新 更多