【问题标题】:using htaccess to redirect to a different domain and path使用 htaccess 重定向到不同的域和路径
【发布时间】:2016-04-02 19:57:31
【问题描述】:

尝试 301 将博客文章从 blog.url.com 重定向到 url.com/blog/*。除了重定向之外,各个帖子的路径也发生了变化,所以我不能使用全局重写规则。

我以为我知道如何做到这一点,但我没有得到预期的结果。这是一个例子:

redirect 301 /post/1234/post-name https://url.com/blog/post-name

但是当我访问url.com/post/1234/post-name时,我最终会被重定向到https://url.com/blogpost/1234/post-name

我做错了什么?

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    事实证明,它与我的 htaccess 中的另一行有关,用于重定向根子域:

    redirect 301 /

    这充当了包罗万象的角色,并弄乱了各个重定向。一旦我将根重定向更改为目录索引所在的redirect 301 /index.html,一切正常。

    【讨论】:

      【解决方案2】:
      #301 Redirects for .htaccess
      
      #Redirect a single page:
      Redirect 301 /pagename.php http://www.domain.com/pagename.html
      
      #Redirect an entire site:
      Redirect 301 / http://www.domain.com/
      
      #Redirect an entire site to a sub folder
      Redirect 301 / domain name/subfolder/
      

      【讨论】:

      • 这就是我所拥有的,但没有按预期工作。它将新域名与旧域名结合起来。
      猜你喜欢
      • 2013-05-18
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 2023-03-08
      • 2018-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多