Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Url rewriting 根据Haproxy中的路径重定向到新域_Url Rewriting_Rewrite_Haproxy - Fatal编程技术网

Url rewriting 根据Haproxy中的路径重定向到新域

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

您好,提前感谢您的帮助

我在我的旧站点上有一个博客,我正在尝试使用haproxy将所有帖子重定向到新站点上的新位置。例如,我想被重定向到301

=>


我已经找到了如何转发
/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

在本例中,acl
old_site
为真,acl
john_blog
为真,acl
jill_blog
为假

reqrep
行将
john blog
替换为
jill blog
,前提是
old_站点
john_blog
ACL均为真,本例就是这样。在这一行之后,示例url是
https://www.oldsite.com/jill-blog/blogpost1

此时acl
john_blog
不再为真,但acl
jill_blog
与uri现在以
/jill blog
开头相同。acl
old_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