# Change response-header from http to https

**URL:** <https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469>\
**Category:** Help!\
**Created:** [February 5, 2024, 8:12am UTC](https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469 "2024-02-05T08:12:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyrano330](https://avatars.discourse-cdn.com/v4/letter/c/3d9bf3/32.png) [@cyrano330](https://discourse.haproxy.org/u/cyrano330)\
**Post date:** [February 5, 2024, 8:12am UTC](https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469/1 "2024-02-05T08:12:47Z")

</div>

Hello everyone,  
I need help with a big problem for me.

I have a frontend that accepts https:// and a backend that only understands http://. So classic SSL offloading. No secret.

Now to the problem. The application on the backend creates a “redirect URI” that the client needs to authenticate against AZURE. Since the backend is addressed with http, the application also generates a redirect URI in the format “[http://xxx.test.com](http://xxx.test.com)”. In order for my authentication to work, I have to change http:// to https://…

I’ve already tried to kill myself. Is there a way to rewrite the response header?

Thanks for all the ideas!

greeting  
cyrano330

---

<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 5, 2024, 9:09am UTC](https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469/2 "2024-02-05T09:09:03Z")

</div>

See **[http-response replace-header](http://docs.haproxy.org/2.8/configuration.html#4.2-http-response%20replace-header)** and **[http-response replace-value](http://docs.haproxy.org/2.8/configuration.html#4.2-http-response%20replace-value)**

---

<div class="post-metadata">

**Author:** ![cyrano330](https://avatars.discourse-cdn.com/v4/letter/c/3d9bf3/32.png) [@cyrano330](https://discourse.haproxy.org/u/cyrano330)\
**Post date:** [February 5, 2024, 11:42am UTC](https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469/3 "2024-02-05T11:42:27Z")

</div>

Hi,

thank you for quick response.

I’ve done some further investigations. The replace-value might be the rigth approach.

The websever send a “HTTP1.1/302 Found” with a generated “Location:” Field. Now the challenge is to change a part of the Location-Field…

Location field is:

https ://login.microsoftonline.com/xxxx-xxxx-xxxx-xxxxx/oauth2/authorize?client\_id=xxxxx-xxxxxx-xxxxx-xxxxxx& **redirect\_uri=http** %3A%2F%[2Fxxx.domain.com](http://2Fxxx.domain.com)%2FTenant%2FSignIn&response\_type=code%20id\_token&scope=openid%20profile&response\_mode=form\_post&nonce=6384 …

I need to replace the “redirect\_uri=http” - part to “redirect\_uri=https”.

Is there a solution to do this with haproxy?

Best  
Henry

---

<div class="post-metadata">

**Author:** ![cyrano330](https://avatars.discourse-cdn.com/v4/letter/c/3d9bf3/32.png) [@cyrano330](https://discourse.haproxy.org/u/cyrano330)\
**Post date:** [February 5, 2024, 11:47am UTC](https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469/4 "2024-02-05T11:47:55Z")

</div>

my attempt is:

http-response replace-value Location ^redirect\_uri=http(.\*)$ redirect\_uri=https\1

in my backend section - but will not work…

---

<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 5, 2024, 12:26pm UTC](https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469/5 "2024-02-05T12:26:56Z")

</div>

I’d imagine that something like this would do the job:

```
http-response replace-header Location ^(.+)(redirect_uri=http)([^s].+)$ \1redirect_uri=https\2

```

---

<div class="post-metadata">

**Author:** ![cyrano330](https://avatars.discourse-cdn.com/v4/letter/c/3d9bf3/32.png) [@cyrano330](https://discourse.haproxy.org/u/cyrano330)\
**Post date:** [February 5, 2024, 12:35pm UTC](https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469/6 "2024-02-05T12:35:03Z")

</div>

Oh thank you. Now th location looks like that:

https: [//login.microsoftonline.com/xxxxxxx-a992-xxxx-xxxx-xxxxxxxxxxxxxxxx/oauth2/authorize?client\_id=a12f6523-xxxxxx-xxx-b6e0-xxxxxxxxxxxxxx&r](https://login.microsoftonline.com/xxxxxxx-a992-xxxx-xxxx-xxxxxxxxxxxxxxxx/oauth2/authorize?client_id=a12f6523-xxxxxx-xxx-b6e0-xxxxxxxxxxxxxx&r) **redirect\_uri=httpsredirect\_uri=http**

Can you please explain the RegEx you used? … is witchcraft for me…

---

<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 5, 2024, 12:55pm UTC](https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469/7 "2024-02-05T12:55:06Z")

</div>

Use [https://regex101.com/](https://regex101.com/) or [https://regexr.com/](https://regexr.com/) to get a detailed explanation of the regex.

---

<div class="post-metadata">

**Author:** ![cyrano330](https://avatars.discourse-cdn.com/v4/letter/c/3d9bf3/32.png) [@cyrano330](https://discourse.haproxy.org/u/cyrano330)\
**Post date:** [February 5, 2024, 3:19pm UTC](https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469/8 "2024-02-05T15:19:24Z")

</div>

Hi lukastribus,

thank you so much for your support and your food for toughts. The solution that works for me is:

![regex](https://us1.discourse-cdn.com/flex016/uploads/haproxy/original/2X/1/1ac9f249966bb2fca52f5b79438b67cc50b214de.jpeg)

Screenshot - because asterisk wont shown…

Maybe this helps another dude facing the same problem…

Best  
Henry

---

<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 5, 2024, 8:43pm UTC](https://discourse.haproxy.org/t/change-response-header-from-http-to-https/9469/9 "2024-02-05T20:43:48Z")

</div>

Ah, I got it, I referred to capture group \2 when I was thinking about group \3.

Referring to \3 or not capturing the `(redirect_uri=http)` (by removing the brackets) would have fixed it.
