# Rewriting Location Header in iRule

**URL:** <https://community.f5.com/t/rewriting-location-header-in-irule/75239>\
**Category:** Technical Forums\
**Tags:** application-delivery\
**Created:** [October 5, 2024, 3:35pm UTC](https://community.f5.com/t/rewriting-location-header-in-irule/75239 "2024-10-05T15:35:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hamza\_derbali](https://avatars.discourse-cdn.com/v4/letter/h/c57346/32.png) [@Hamza\_derbali](https://community.f5.com/u/Hamza_derbali)\
**Post date:** [October 5, 2024, 3:35pm UTC](https://community.f5.com/t/rewriting-location-header-in-irule/75239/1 "2024-10-05T15:35:27Z")

</div>

Hello everyone,

I’m trying to find a way to manipulate the HTTP::header location.

For each redirection containing a location header from the backend server, I need to rewrite just the host part of the URL following this rule:

If the location contains “[http://webserver01:8282](http://webserver01:8282)”, the iRule should rewrite the host to “[https://externallink.com](https://externallink.com)” while preserving the rest of the URL.

For example:  
[http://webserver01:8282/login](http://webserver01:8282/login) should be rewritten to [https://externallink.com/login](https://externallink.com/login).

Any help to achieve this would be greatly appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![Enes\_Afsin\_Al](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/enes_afsin_al/32/15359_2.png) [@Enes\_Afsin\_Al](https://community.f5.com/u/Enes_Afsin_Al)\
**Post date:** [October 6, 2024, 1:56pm UTC](https://community.f5.com/t/rewriting-location-header-in-irule/75239/2 "2024-10-06T13:56:38Z")

</div>

Hi Hamza,

```tcl
when HTTP_RESPONSE {
    if { [HTTP::header Location] starts_with "http://webserver01:8282"} {
        HTTP::header replace Location [string map {"http://webserver01:8282" "https://externallink.com"} [HTTP::header Location]]
    }
}

```

---

<div class="post-metadata">

**Author:** ![Hamza\_derbali](https://avatars.discourse-cdn.com/v4/letter/h/c57346/32.png) [@Hamza\_derbali](https://community.f5.com/u/Hamza_derbali)\
**Post date:** [October 7, 2024, 1:02am UTC](https://community.f5.com/t/rewriting-location-header-in-irule/75239/3 "2024-10-07T01:02:31Z")

</div>

Thanks.
