# Backend redirects

**URL:** <https://discourse.haproxy.org/t/backend-redirects/2540>\
**Category:** Help!\
**Created:** [May 29, 2018, 7:57am UTC](https://discourse.haproxy.org/t/backend-redirects/2540 "2018-05-29T07:57:13Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![pathet](https://avatars.discourse-cdn.com/v4/letter/p/b4bc9f/32.png) [@pathet](https://discourse.haproxy.org/u/pathet)\
**Post date:** [May 29, 2018, 7:57am UTC](https://discourse.haproxy.org/t/backend-redirects/2540/1 "2018-05-29T07:57:13Z")

</div>

Hello,

we have a little configuration problem, maybe some guru can help us. 🙂

Haproxy 1.7.11

[blog.example.com](http://blog.example.com) = blog  
[blogde.example.com](http://blogde.example.com) = blogde

We configured some redirects in the htaccess file of the backend servers.  
The redirect should forward from blogde to blog/de/de/. Blogde is an CNAME of blog.

We configured an SSL Cert for “blog” in the frontend config in the Haproxy config. So now the users type in “blogde” and they get an certificate error (SSL\_ERROR\_BAD\_CERT\_DOMAIN).  
If the users try to reach “blog”, everything is fine.

Is it possible to use the htaccess redirects on the backend servers ?

Thanks in advance.

regards  
Patrick

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [May 29, 2018, 6:06pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/2 "2018-05-29T18:06:16Z")

</div>

You mean the users should always see “[blog.example.com](http://blog.example.com)”, while the backend expects the host Header [blogde.example.com](http://blogde.example.com)?

You can just (re)set the Host header in the backend:  
`http-request set-header Host blogde.example.com`

---

<div class="post-metadata">

**Author:** ![pathet](https://avatars.discourse-cdn.com/v4/letter/p/b4bc9f/32.png) [@pathet](https://discourse.haproxy.org/u/pathet)\
**Post date:** [May 29, 2018, 7:42pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/3 "2018-05-29T19:42:30Z")

</div>

> [@lukastribus](#):
>
> http-request set-header Host [blogde.example.com](http://blogde.example.com)

thanks for your answer.Yes the users should always see “blog/.example/.com” because the SSL Cert is based on blog/.example/.com.  
Its a good information, but i want to redirect to an url (not fix) for example like this

> “blog/.example/.com/blog/startPage.faces?blogId=599”

The blog id (599) can change if the reached url is (for example)

> “bloges/.example/.com”

it should redirect to

> “blog/.example/.com/blog/startPage.faces?blogId=520”

The htaccess entrys on the backend servers looks like this

> RewriteCond %{HTTP\_HOST} blogde/.example/.com [NC]  
> RewriteRule ^(.\*)$ http(s)://blog/.example/.com/blog/startPage.faces?storeId=599 [R=302]

or like

> RewriteCond %{HTTP\_HOST} bloges/.example/.com [NC]  
> RewriteRule ^(.\*)$ http(s)://blog.example.com/blog/startPage.faces?storeId=502 [R=302]

Hope I explained it clear, its hard, because I can use only two URLs 🙂

thanks again for your help.

regards  
Patrick

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [May 29, 2018, 11:22pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/4 "2018-05-29T23:22:59Z")

</div>

I have bumped your trust level, the forum by default blocks a lot of things from new users for spam reasons.

Let’s see if I understood this correctly, we actually redirect based on a wrong hostname where the SSL certificate doesn’t match in the first place? I’m not sure I understand what you want to achieve and how you want to avoid certificate mismatches then.

```
http-request redirect location https://blog.example.com/blog/startPage.faces?storeId=599 if { hdr(host) -i blogde.example.com }
http-request redirect location https://blog.example.com/blog/startPage.faces?storeId=502 if { hdr(host) -i bloges.example.com }
```

---

<div class="post-metadata">

**Author:** ![pathet](https://avatars.discourse-cdn.com/v4/letter/p/b4bc9f/32.png) [@pathet](https://discourse.haproxy.org/u/pathet)\
**Post date:** [May 30, 2018, 8:14am UTC](https://discourse.haproxy.org/t/backend-redirects/2540/5 "2018-05-30T08:14:05Z")

</div>

thanks for the trust level 🙂

> http-request redirect location [https://blog.example.com/blog/startPage.faces?storeId=599](https://blog.example.com/blog/startPage.faces?storeId=599) if { hdr(host) -i [blogde.example.com](http://blogde.example.com) }  
> http-request redirect location [https://blog.example.com/blog/startPage.faces?storeId=502](https://blog.example.com/blog/startPage.faces?storeId=502) if { hdr(host) -i [bloges.example.com](http://bloges.example.com) }

works great, you are the best, thank you !!  
I have another challenge, additionally to the first one.The htaccess on the backend looks like this

> RewriteCond %{HTTP\_HOST} blogde.example.com [NC]  
> RewriteRule ^ **webapp** (/\*)$ [https://webappblog.example.com/blog/app/?shop=599](https://webappblog.example.com/blog/app/?shop=599) [L,R=302]

If someone want to go to [blogde.example.com/webapp](http://blogde.example.com/webapp) , the users should redirected to [https://webappblog.example.com/blog/app/?shop=599](https://webappblog.example.com/blog/app/?shop=599) . Is this also possible, additionally to the first redirect in my post before ?

Sorry I am new at using haproxy…

So many thanks for your great help.

kind regards  
Patrick

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [May 30, 2018, 8:21am UTC](https://discourse.haproxy.org/t/backend-redirects/2540/6 "2018-05-30T08:21:56Z")

</div>

Sure, just put the following rule before the other blogde rule:

```
http-request redirect location https://webappblog.example.com/blog/app/?shop=599 if { hdr(host) -i blogde.example.com } { path_beg /webapp/ }
```

---

<div class="post-metadata">

**Author:** ![pathet](https://avatars.discourse-cdn.com/v4/letter/p/b4bc9f/32.png) [@pathet](https://discourse.haproxy.org/u/pathet)\
**Post date:** [May 30, 2018, 1:03pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/7 "2018-05-30T13:03:06Z")

</div>

thanks again, but I´m landing on

> [https://blog.example.com/blog/startPage.faces?storeId=599](https://blog.example.com/blog/startPage.faces?storeId=599)

this is the order in the config file

> http-request redirect location [https://webappblog.example.com/blog/app/?shop=599](https://webappblog.example.com/blog/app/?shop=599) if { hdr(host) -i [blogde.example.com](http://blogde.example.com) } { path\_beg /webapp/ }  
> http-request redirect location [https://blog.example.com/blog/startPage.faces?storeId=599](https://blog.example.com/blog/startPage.faces?storeId=599) if { hdr(host) -i [blogde.example.com](http://blogde.example.com) }

the http log looks like this:

> May 30 14:36:01 de-haproxy-jshop haproxy[5247]: 10.98.150.72:53278 [30/May/2018:14:36:01.843] jshop\_80 jshop\_80/ 0/-1/-1/-1/0 302 136 - - LR-- 2/2/0/0/0 0/0 “GET /webapp HTTP/1.1”

> May 30 14:36:01 de-haproxy-jshop haproxy[5247]: 10.98.150.72:53279 [30/May/2018:14:36:01.859] jshop\_443~ jshop/jshop10 0/0/1/12/14 200 3827 - - --NR 3/1/0/0/0 0/0 “GET /blog/startPage.faces?storeId=599 HTTP/1.1”

I think the redirect to [https://webappblog.example.com/blog/app/?shop=599](https://webappblog.example.com/blog/app/?shop=599) is ignored.

Do you have another hint for me ? 🙂

many thanks.

kind regards  
Patrick

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [May 30, 2018, 1:24pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/8 "2018-05-30T13:24:45Z")

</div>

Yeah, looks like the second statement matches anyway. We will need to negate it there:

```
http-request redirect location https://webappblog.example.com/blog/app/?shop=599 if { hdr(host) -i blogde.example.com } { path_beg /webapp/ }
http-request redirect location https://blog.example.com/blog/startPage.faces?storeId=599 if { hdr(host) -i blogde.example.com } !{ path_beg /webapp/ }
```

---

<div class="post-metadata">

**Author:** ![pathet](https://avatars.discourse-cdn.com/v4/letter/p/b4bc9f/32.png) [@pathet](https://discourse.haproxy.org/u/pathet)\
**Post date:** [May 30, 2018, 1:51pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/9 "2018-05-30T13:51:39Z")

</div>

many thanks ! works perfect.  
I dont know which answer i should mark as solution, you gave me so much solutions. You save me so much time.

Many thanks again.

kind regards  
Patrick

---

<div class="post-metadata">

**Author:** ![pathet](https://avatars.discourse-cdn.com/v4/letter/p/b4bc9f/32.png) [@pathet](https://discourse.haproxy.org/u/pathet)\
**Post date:** [February 8, 2019, 9:55am UTC](https://discourse.haproxy.org/t/backend-redirects/2540/10 "2019-02-08T09:55:29Z")

</div>

got another request about this topic…is it also possible if someone try to reach [https://blogde.example.com](https://blogde.example.com) direct to redirect the request to [https://blog.example.com/blog/startPage.faces?storeId=599](https://blog.example.com/blog/startPage.faces?storeId=599) ?

thanks.

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 8, 2019, 5:35pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/11 "2019-02-08T17:35:17Z")

</div>

Sure the path in this case is `/` :

```
http-request redirect location https://blog.example.com/blog/startPage.faces?storeId=599 if { hdr(host) -i blogde.example.com } { path / }
```

---

<div class="post-metadata">

**Author:** ![pathet](https://avatars.discourse-cdn.com/v4/letter/p/b4bc9f/32.png) [@pathet](https://discourse.haproxy.org/u/pathet)\
**Post date:** [February 11, 2019, 4:16pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/12 "2019-02-11T16:16:55Z")

</div>

thanks for your reply. I got also an ERR\_CERT\_COMMON\_NAME\_INVALID with { path / } added.  
very strange…

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 11, 2019, 4:28pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/13 "2019-02-11T16:28:31Z")

</div>

That doesn’t have anything to do with the redirect and the `path /`. Look at the actual problem instead (certificate name mismatch).

---

<div class="post-metadata">

**Author:** ![pathet](https://avatars.discourse-cdn.com/v4/letter/p/b4bc9f/32.png) [@pathet](https://discourse.haproxy.org/u/pathet)\
**Post date:** [February 11, 2019, 4:44pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/14 "2019-02-11T16:44:25Z")

</div>

this is correct, but the certificate is installed on [blog.example.com](http://blog.example.com) and not on [blogde.example.com](http://blogde.example.com). Thats why we want to redirect to [blog.example.com](http://blog.example.com) 🙂

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [February 11, 2019, 5:10pm UTC](https://discourse.haproxy.org/t/backend-redirects/2540/15 "2019-02-11T17:10:55Z")

</div>

Then you need to get a certificate for `blogde.example.com`.
