【问题标题】:haproxy absolute redirect for an entire domain整个域的 haproxy 绝对重定向
【发布时间】:2017-11-10 03:46:51
【问题描述】:

我已经在谷歌上搜索了几个小时,但没有找到必须简单的东西。

我正在使用 haproxy 1.7 并尝试将所有流量从一个域重定向到另一个“登录页面”并部分成功。我可以得到一个基本的重定向来工作,但是如果有人使用书签链接,他们会得到一个 404,因为新域上不存在 URL。

domain1.com/foo 或 domain1.com/bar/baz/whatever 都需要重定向到 domain2.com/landing 我在任何示例中都找不到关于如何执行此操作的 acl。我知道在 reidrect 之前它必须是某种重写规则,但我不能让一个工作。

这是我尝试过的一些设置:

#        reqrep ^([^\ ]*)\ /(.*)  \1\ /\2 if domain1_host
#        redirect location https://domain2.com/landing  code 301  prefix /landing drop-query if domain1_host
#        http-request replace-header X-REWRITE ^/.*?$ /\1 if domain1_host
#        reqrep ^([^\ ]*\ /)(.*) \1landing\2 if domain1_host
#        reqrep ^([^\ ]*\ /)[/]?(.*)     \1\2 if domain1_host
#        reqrep ^([^\ ]*)\ /(.*) \1\ /\2 if domain1_host
#        redirect prefix https://domain2.com/landing code 301  if domain1_host
redirect scheme https://domain2.com/landing code 301  if domain1_host

如果有人对我错过的内容有一些建议,我真的很感激一些方向。

【问题讨论】:

    标签: haproxy


    【解决方案1】:

    与此作斗争,终于找到了答案。我是对的,这很简单。不需要 reqrep 或重定向规则之外的重写。简单的重定向位置到目标位置。绝对是重写。

    redirect location https://domain2.com/landing code 301 if domain1_host    
    

    这就是我们所需要的。

    我希望网络上有一个更好的例子来说明重定向位置何时有用,但我怀疑大多数人会比这样的重定向更频繁地需要 acl 或重定向前缀。我希望将来的其他人会发现这篇文章很有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-13
      • 2015-08-26
      • 2012-10-26
      • 2017-01-30
      • 1970-01-01
      • 2019-09-17
      • 2017-08-25
      • 1970-01-01
      相关资源
      最近更新 更多