stecog
stecog

Reputation: 2344

haproxy - redirect specific domain/path to other domain

i need redirect request from specific domain/path to other domain with same path, eg.

domain.com/foo/everything --> example.com/foo/everything

I think need use url_reg but I can't understand how to handle the redirect, maybe it could be such a thing?

acl redirect-foo   url_reg -i      ^domain.com\/foo\/*
http-request redirect code 301 location http://example.com/foo/ if redirect-foo

but obviously it doesn't work, thank anyone who can help me

Upvotes: 0

Views: 3110

Answers (1)

Aleksandar
Aleksandar

Reputation: 2642

You can use the following snipplet

acl host_match hdr(host) -i domain.com
acl path_match path_beg  -i /foo/

http-request redirect code 301 location http://example.com/%[capture.req.uri] if host_match path_match

The acl's are described in the Documentation and in following Blog post.

Using ACLs to form conditions
Introduction to HAProxy ACLs

Documentation for capture.req.uri

Upvotes: 3

Related Questions