# URL redirection issue

**URL:** <https://discourse.haproxy.org/t/url-redirection-issue/7247>\
**Category:** Help!\
**Created:** [December 25, 2021, 2:25am UTC](https://discourse.haproxy.org/t/url-redirection-issue/7247 "2021-12-25T02:25:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vijayanand](https://avatars.discourse-cdn.com/v4/letter/v/3ab097/32.png) [@Vijayanand](https://discourse.haproxy.org/u/Vijayanand)\
**Post date:** [December 25, 2021, 2:25am UTC](https://discourse.haproxy.org/t/url-redirection-issue/7247/1 "2021-12-25T02:25:54Z")

</div>

Hi Team,

I am facing issue in URL redirection. Need your help and suggestion.

Using : HA-Proxy version 2.0.4 2019/08/06 - [https://haproxy.org/](https://haproxy.org/)

Created HTTP & HTTPS Group.

When user hit URL “website.in”.The default website.in will go the default http & https group.

When user hit below mentioned URL.We have configured acl for below mentioned domain to point to specific backend server.  
abc.website.in  
xyz.website.in

Till now everything is working fine. We have requirement from development Team.

When user hit [http://abc.website.in](http://abc.website.in) this need to be redirected to [https://abc.website.in/service](https://abc.website.in/service). – We have configured ACL is working fine.

When user hit [https://abc.website.in](https://abc.website.in) this need to be redirected to [https://abc.website.in/service](https://abc.website.in/service) – When we configure ACL this is going to default backend not going to specific backend server.

---

<div class="post-metadata">

**Author:** ![senseivita](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/senseivita/32/1596_2.png) [@senseivita](https://discourse.haproxy.org/u/senseivita)\
**Post date:** [December 29, 2021, 11:09pm UTC](https://discourse.haproxy.org/t/url-redirection-issue/7247/2 "2021-12-29T23:09:23Z")

</div>

```auto
frontend port80
  ...
  acl https ssl_fc
  http-request redirect location https://abc.website.in/service code 302 unless https
  # ...or 301(permanent) or 303(new GET request), personally I'd go with 303 because it instructs
  # the browser to perform a GET request. APIs don't work with redirects so if you've already broken
  # things, might as well go full in. :)
  ...
  # It seems you're not serving non-TLS content, so you don't need a server here.

frontend port443
  ...
  http-request set-var(txn.txnpath) path
  http-request set-var(txn.txnhost) hdr(host)
  # ↑↑ Captures stuff in variables used in the transactions back and forth ↑↑
  acl xyz.website.in var(txn.txnhost) -m str -i xyz.website.in
  acl abc.website.in var(txn.txnhost) -m str -i abc.website.in
  # ↑↑ A default backend is only needed if you're going to serve content on a wildcard address ↑↑
  # (anything else that you didn't specify beforehand), so having this is a restriction on
  # where (as in location) can content be requested from. If it were "-m end -i website.in" you'd
  # accept everything not "xyz." with a simple "*" CNAME to your main [sub]domain.
  acl path-is-correct var(txn.txnpath) -m beg -i /service
  http-request set-path /service/%[path] if abc.website.in !path-is-correct
  # ↑↑ Might not work if your web server needs to have trailing "/" ↑↑
  # OK: .../service/index.html .../service/image.svg .../service/[hiddenvoodoo] NOT OK: .../service
  ...
  use_backend xyz.website.in:443 if xyz.website.in
  use_backend abc.website.in:443 if abc.website.in
  ...

backend xyz.website.in:443
  ...

backend abc.website.in:443
  ...

```

I think this might be it. You left a lot of stuff out so I’m filling out blank as best and as generically as I can. I’m a newbie too, so you might be best if you wait for a second opinion though. Good luck! 🙂

---

<div class="post-metadata">

**Author:** ![Vijayanand](https://avatars.discourse-cdn.com/v4/letter/v/3ab097/32.png) [@Vijayanand](https://discourse.haproxy.org/u/Vijayanand)\
**Post date:** [May 20, 2022, 1:05pm UTC](https://discourse.haproxy.org/t/url-redirection-issue/7247/3 "2022-05-20T13:05:29Z")

</div>

Thanks for your suggestion.
