【问题标题】:Redirect all deeplinks to new domain with slight change in all URL's将所有深层链接重定向到新域,所有 URL 都略有变化
【发布时间】:2014-11-27 11:32:23
【问题描述】:

我正在尝试将 DomainA 的所有页面重定向到 DomainB,但 URL 结构略有变化。

例如:

我需要重定向:

http://www.domaina.com/cars/fast-motors -> http://www.domainb.com/vehicles/fast-cars http://www.domaina.com/cars/slow-motors -> http://www.domainb.com/vehicles/slow-cars http://www.domaina.com/cars/red-motors -> http://www.domainb.com/vehicles/red-cars http://www.domaina.com/cars/pink-motors -> http://www.domainb.com/vehicles/pink-cars

我可以像这样设法将所有网址重定向到新域:

RewriteRule 上的 RewriteEngine ^cars/(.*)$ http://www.domainb.com/vehicles/$1 [R=301,L]

但我不知道如何更改最后一个单词。这些网址有数千个,所以我无法手动列出 301。我基本上需要将所有网址重定向到新域,但将/cars/ 切换到/vehicles/-motors-cars

任何帮助表示赞赏。

谢谢

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect http-status-code-301


    【解决方案1】:

    您可以在 .htaccess 文件中使用它:

    RewriteEngine On
    RewriteRule ^cars/(.*)-motors/? http://www.domainb.com/vehicles/$1-cars [R=302,L]
    

    当测试正常时将[R=302] 更改为[R=301]

    【讨论】:

      猜你喜欢
      • 2020-04-30
      • 2012-09-17
      • 2015-07-17
      • 1970-01-01
      • 1970-01-01
      • 2015-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多