# remove tcp port from Location header in redirect

**URL:** <https://community.f5.com/t/remove-tcp-port-from-location-header-in-redirect/59847>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [May 2, 2012, 10:07am UTC](https://community.f5.com/t/remove-tcp-port-from-location-header-in-redirect/59847 "2012-05-02T10:07:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dirken](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@dirken](https://community.f5.com/u/dirken)\
**Post date:** [May 2, 2012, 10:07am UTC](https://community.f5.com/t/remove-tcp-port-from-location-header-in-redirect/59847/1 "2012-05-02T10:07:34Z")

</div>

Hi folks, newbie and tasked to remove the tcp port from a redirect’s Location header. Without a test system I cannot check it and would appreciate any feedback before going live. Would this iRule work?

when HTTP\_RESPONSE {

if { [HTTP::is\_redirect] } {

[string map [list :52600 “”] [HTTP::header Location]]

}

}

---

<div class="post-metadata">

**Author:** ![MiLK\_MaN](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@MiLK\_MaN](https://community.f5.com/u/MiLK_MaN)\
**Post date:** [May 2, 2012, 10:54am UTC](https://community.f5.com/t/remove-tcp-port-from-location-header-in-redirect/59847/2 "2012-05-02T10:54:01Z")

</div>

Try:

when HTTP\_RESPONSE {

if { [HTTP::is\_redirect] } {

HTTP::header replace Location [getfield [HTTP::header value Location] : 1]

}

}

---

<div class="post-metadata">

**Author:** ![dirken](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@dirken](https://community.f5.com/u/dirken)\
**Post date:** [May 2, 2012, 11:51am UTC](https://community.f5.com/t/remove-tcp-port-from-location-header-in-redirect/59847/3 "2012-05-02T11:51:35Z")

</div>

Two problems:

1. if the Location contains an absolute path like “[https://somehost:52600](https://somehost:52600)”, then this iRule would redirect me to “https” with nothing behind it, correct?

2. if the Location contains an URI behind the host like “somehost:52600/somepath/somefile”, then the iRule would redirect me to “somehost” without any path, correct?

---

<div class="post-metadata">

**Author:** ![MiLK\_MaN](https://avatars.discourse-cdn.com/v4/letter/m/8491ac/32.png) [@MiLK\_MaN](https://community.f5.com/u/MiLK_MaN)\
**Post date:** [May 2, 2012, 10:16pm UTC](https://community.f5.com/t/remove-tcp-port-from-location-header-in-redirect/59847/4 "2012-05-02T22:16:47Z")

</div>

You are right. Apologies for not considering that.

when HTTP\_RESPONSE {

if { [HTTP::is\_redirect] } {

regsub -all “:52600” [HTTP::header Location] “” newlocation

HTTP::header replace Location $newlocation

}

}

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [May 2, 2012, 10:56pm UTC](https://community.f5.com/t/remove-tcp-port-from-location-header-in-redirect/59847/5 "2012-05-02T22:56:25Z")

</div>

You could use string commands for this as well. Here are a few options which should be a bit more efficient than regsub:

> **[DevCentral](https://community.f5.com/)**
>
> DevCentral is an online technical community where engineers and practitioners collaborate, share knowledge, and solve problems related to F5 technologies and industry trends.

Aaron
