【问题标题】:Htaccess multiple redirects not workingHtaccess多个重定向不起作用
【发布时间】:2016-11-09 02:33:53
【问题描述】:

我们有一个新域名并希望重定向我们的老客户。 现在我们有一个小改动,我们正在从 nl 域更改为 com,因此我们希望我们的 nl ​​客户转到 .com/nl,英语客户从 /us/ 转到 .com 它需要是 301 重定向并发送 URL。 所以我们现在得到了这个,但它不起作用

RewriteEngine on
RewriteRule ^olddomain\.nl/ca$ /newdomain.com/ca/? [L,R=301]
RewriteRule ^ olddomain\.nl/dk$ /newdomain.com/dk/? [L,R=301]
RewriteRule ^ olddomain\.nl/us$ /newdomain.com/? [L,R=301]
RewriteRule ^ olddomain\.nl$ /newdomain.com/nl? [L,R=301]

我们是否做错了我很恐慌,因为我们明天需要上线。希望有人可以帮助我

好的,所以我们再进一步。

RewriteEngine on
#olddomain/us =>newdomain/
RewriteRule ^us/?$ http://newdomain.com/ [NE,L,R]
#olddomain.nl/ =>newdomain/nl
RewriteRule ^$ http://newdomain.com/nl/ [NE,L,R]
#olddomain/others =>newdomain/others
RewriteRule ^(ca|dk)/ http://newdomain.com/$1 [NE,L,R=301]

不工作

  1. olddomain.nl 到 newdomain.com/nl/
  2. 将旧 URL 发送到新页面,如 keep olddomain.nl/oldpage.php

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您可以在 olddomain/.htaccess 中使用以下规则:

    RewriteEngine on
    #1)olddomain/us =>newdomain/
    RewriteRule ^us/?(.*)?$ http://newdomain.com/$1 [NE,L,R]
    #2)olddomain/others =>newdomain/others
    RewriteRule ^(ca|dk)(/.*)?$ http://newdomain.com/$1$2 [NE,L,R=301]
    #3)olddomain.nl/page =>newdomain/nl/page
    RewriteRule ^(.*)$ http://newdomain.com/nl/$1 [NE,L,R]
    

    【讨论】:

    • 谢谢几乎解决了,唯一的问题是如果我去 olddomain.nl 它不会去 newdomain.com/nl/ 如果我去 olddomain.nl/ca/testfolder 它说 404 not found 而不是重定向
    • 仍然不能完全工作我很高兴你能帮助我。 olddomain.nl 去 newdomain.com 不行 应该是 newdomain.com/nl/ oldomain.nl/us/ 去 newdomain.com 好 oldomain.nl/us/test123 去 newdomain.com 几乎没问题 /test123 不见了跨度>
    • @wesley 抱歉,我没有注意到。有一个轻微的错字。请清除您的浏览器缓存并立即尝试更新版本。
    • 它几乎可以与 dk 和 ca 一起使用,它也完全可以重定向到 nl,但在前两个上,其他所有东西都丢失了,比如 olddomain.nl/testpage.php 或 olddomain.nl/us/page/它应该将其发送到新域,例如 newdomain.com/nl/testpage.php newdomain.com/page/
    • @Wesley 尝试新的编辑。我将 nl 规则放在第 3 位以避免覆盖规则。
    猜你喜欢
    • 2020-05-13
    • 2015-03-07
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    相关资源
    最近更新 更多