【问题标题】:How to use htaccess to redirect to a new domain with different url structure如何使用 htaccess 重定向到具有不同 url 结构的新域
【发布时间】:2015-08-21 10:32:23
【问题描述】:

我正在尝试从旧网站重定向到新网站:

旧:blog.example.com 新:www.example.com/blog

为了实现上述目的,我得到了这个.htaccess

RewriteCond %{HTTP_HOST} ^blog.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^blog.example.com$
RewriteRule (.*)$ http://www.exmaple.com/blog/$1 [R=301,L]
RedirectMatch 301 ^/bournemouth-datacentre/$ http://www.example.com/blog/

而且效果很好。最重要的是我需要重定向(示例):

旧:blog.example.com/somecategory/some-title-here/

新:www.example.com/blog/some-title-here

请注意,我丢失了域和标题之间的类别,并将其替换为博客。没关系。

谁能建议我如何实现子域到域,然后是博客重定向以及类别重定向?

重要提示:旧站点是 WP,新站点是 Drupal!

谢谢!

【问题讨论】:

    标签: wordpress apache .htaccess mod-rewrite redirect


    【解决方案1】:

    你可以使用:

    RewriteCond %{HTTP_HOST} ^blog\.example\.com$
    RewriteRule ^(?:bournemouth-datacentre|general|london)/(.*)$ http://www.example.com/blog/$1 [L,NC,R=301]
    
    RewriteCond %{HTTP_HOST} ^blog\.example\.com$
    RewriteRule ^(.*)$ http://www.exmaple.com/blog/$1 [R=301,L]
    

    【讨论】:

    • 不幸的是,这不起作用。当我添加并尝试以下网址时:http://blog.example.co.uk/bournemouth-datacentre/title/ 我得到了www.example.co.uk/blog/bournemouth-datacentre/title/
    • 效果很好!并且为了添加除bournemouth-datacentre之外的其他类别(例如,类别为bournemouth-datacentregenerallondon等。全部重定向到/blog?我是否只需添加另一个RewriteRule在第一个下面?
    • 查看更新答案以处理其他类别。
    • 完美运行!非常感谢!
    【解决方案2】:

    试试下面的代码:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^blog.example.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^blog.example.com [NC]
    RewriteRule ^(.*)$ /bournemouth-datacentre/$1 [L,R=301,NC]
    

    【讨论】:

      猜你喜欢
      • 2015-05-07
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      • 2013-01-07
      相关资源
      最近更新 更多