Url rewriting 根据Haproxy中的路径重定向到新域
您好,提前感谢您的帮助 我在我的旧站点上有一个博客,我正在尝试使用haproxy将所有帖子重定向到新站点上的新位置。例如,我想被重定向到301 =>Url rewriting 根据Haproxy中的路径重定向到新域,url-rewriting,rewrite,haproxy,Url Rewriting,Rewrite,Haproxy,您好,提前感谢您的帮助 我在我的旧站点上有一个博客,我正在尝试使用haproxy将所有帖子重定向到新站点上的新位置。例如,我想被重定向到301 => 我已经找到了如何转发/john blog的流量,但还没有找到如何进行重写,以便将旧站点上的/john blog/blogpost1转发到新站点上的/jill blog/blogpost1 这就是我能想到的: frontend https option http-server-close reqadd X-Forwarded-Prot
我已经找到了如何转发
/john blog
的流量,但还没有找到如何进行重写,以便将旧站点上的/john blog/blogpost1
转发到新站点上的/jill blog/blogpost1
这就是我能想到的:
frontend https
option http-server-close
reqadd X-Forwarded-Proto:\ https
acl old_site hdr(host) -i www.oldsite.com
acl john_blog path_beg /john-blog
acl jill_blog path_beg /jill-blog
reqrep ^([^\ ]*\ /)john-blog(.*) \1jill-blog\2 if old_site john_blog
redirect prefix https://www.newsite.com code 301 if old_site jill_blog
此配置的唯一缺点是它还将重定向https://www.oldsite.com/jill-blog
=>https://www.newsite.com/jill-blog
。如果这是一个问题,我可以试着找出别的办法
它是如何工作的
我将遵循并举例请求https://www.oldsite.com/john-blog/blogpost1
在本例中,aclold_site
为真,acljohn_blog
为真,acljill_blog
为假
reqrep
行将john blog
替换为jill blog
,前提是old_站点
和john_blog
ACL均为真,本例就是这样。在这一行之后,示例url是https://www.oldsite.com/jill-blog/blogpost1
此时acljohn_blog
不再为真,但acljill_blog
与uri现在以/jill blog
开头相同。aclold_site
仍然正确
重定向
行中的重定向位置由附加了原始uri的提供字符串确定。在本例中,提供的字符串为https://www.newsite.com
而追加的uri是/jill blog/blogpost1
,导致reditect url为https://www.newsite.com/jill-blog/blogpost1
希望能有所帮助。@JamesStewy,我有一个类似的http重定向请求,但无法使其工作-
frontend https
option http-server-close
reqadd X-Forwarded-Proto:\ https
acl old_site hdr(host) -i www.oldsite.com
acl john_blog path_beg /john-blog
acl jill_blog path_beg /jill-blog
reqrep ^([^\ ]*\ /)john-blog(.*) \1jill-blog\2 if old_site john_blog
redirect prefix https://www.newsite.com code 301 if old_site jill_blog