# Need Irule for redirection for port translation

**URL:** <https://community.f5.com/t/need-irule-for-redirection-for-port-translation/48772>\
**Category:** Technical Forums\
**Tags:** irules, security, big-ip\
**Created:** [April 10, 2020, 4:20am UTC](https://community.f5.com/t/need-irule-for-redirection-for-port-translation/48772 "2020-04-10T04:20:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![VikashC](https://avatars.discourse-cdn.com/v4/letter/v/5f8ce5/32.png) [@VikashC](https://community.f5.com/u/VikashC)\
**Post date:** [April 10, 2020, 4:20am UTC](https://community.f5.com/t/need-irule-for-redirection-for-port-translation/48772/1 "2020-04-10T04:20:06Z")

</div>

Hello team,

I am trying to configure one web service. Post configuration when i tried to access service using F5 VS, the requests redirected to the http host with automatically addition of service port 8080 which is backend webserver port.

e.g. i was trying to access web service using [https://abc.com](https://abc.com) --\> it got redirected to [http://abc.com:8080](http://abc.com:8080)

I am sure, F5 is not adding this port. This is happening due to hard coded port from application itself but application team member is not able to find it under application config. I am looking for an iRule which will help to redirect **'[http://abc.com:8080](http://abc.com:8080)**’ to **[https://abc.com](https://abc.com)** again.

I tried several which are available on internet but somehow not working for me. Please help me here.

---

<div class="post-metadata">

**Author:** ![Mayur\_Sutare](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/mayur_sutare/32/5035_2.png) [@Mayur\_Sutare](https://community.f5.com/u/Mayur_Sutare)\
**Post date:** [April 10, 2020, 4:29am UTC](https://community.f5.com/t/need-irule-for-redirection-for-port-translation/48772/2 "2020-04-10T04:29:19Z")

</div>

Hello Vikash,

Please try below iRule -

**when HTTP\_REQUEST {**

**if { [string tolower [HTTP::host]] contains “[abc.com](http://abc.com)” } {**

**pool abc-pool**

**}**

**HTTP::header remove Accept-Encoding**

**STREAM::disable**

**}**

**when HTTP\_RESPONSE {**

**# Disable the stream filter for server responses**

**STREAM::disable**

**# Enable the stream filter for text responses only**

**if {[HTTP::header value Content-Type] contains “text”}{**

**# Replace ‘old\_text’ with ‘new\_text’**

**STREAM::expression {@[http://abc.com:8080/@https://abc.com/@](http://abc.com:8080/@https://abc.com/@)}**

**# Enable the stream filter for this response only**

**STREAM::enable**

**}**

**}**

Hope it works for you!

Mayur

---

<div class="post-metadata">

**Author:** ![VikashC](https://avatars.discourse-cdn.com/v4/letter/v/5f8ce5/32.png) [@VikashC](https://community.f5.com/u/VikashC)\
**Post date:** [April 10, 2020, 7:15am UTC](https://community.f5.com/t/need-irule-for-redirection-for-port-translation/48772/3 "2020-04-10T07:15:29Z")

</div>

Thanks Mayur!

I will try above iRule and update you.

---

<div class="post-metadata">

**Author:** ![VikashC](https://avatars.discourse-cdn.com/v4/letter/v/5f8ce5/32.png) [@VikashC](https://community.f5.com/u/VikashC)\
**Post date:** [April 12, 2020, 10:32am UTC](https://community.f5.com/t/need-irule-for-redirection-for-port-translation/48772/4 "2020-04-12T10:32:21Z")

</div>

,

It worked perfectly for me!! Thanks for the help, appreciate it !!

Just one question here, if i want to add one more host redirection in the same iRule then how will be the formatting? This is because, mostly we have multiple host traffic behind one VS. So we have commons iRules. e.g. under above iRULE itself, i want to add redirection from **[http://xyz.com:8080](http://xyz.com:8080)** to **[https://xyz.com](https://xyz.com).**

**What will be my iRule?**

---

<div class="post-metadata">

**Author:** ![Mayur\_Sutare](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/mayur_sutare/32/5035_2.png) [@Mayur\_Sutare](https://community.f5.com/u/Mayur_Sutare)\
**Post date:** [April 12, 2020, 12:54pm UTC](https://community.f5.com/t/need-irule-for-redirection-for-port-translation/48772/5 "2020-04-12T12:54:32Z")

</div>

Hello &nbsp;,

Either you can have separate iRule for each host URL and attached all such iRules to the required Virtual Server or

You can add all the URLs under single iRule as given below -

when HTTP\_REQUEST {

if { [string tolower [HTTP::host]] contains “[abc.com](http://abc.com)” } {

pool abc-pool

}**elseif { [string tolower [HTTP::host]] contains “[xyz.com](http://xyz.com)”} {**

**pool xyz-pool**

}

HTTP::header remove Accept-Encoding

STREAM::disable

}

when HTTP\_RESPONSE {

# Disable the stream filter for server responses

STREAM::disable

# Enable the stream filter for text responses only

if {[HTTP::header value Content-Type] contains “text”}{

# Replace ‘old\_text’ with ‘new\_text’

STREAM::expression {@[http://abc.com:8080/@https://abc.com/@\*\*\\](http://abc.com:8080/@https://abc.com/@**%5C%5C)\*\*

**@[http://xyz.com:8080/@https://xyz.com/@](http://xyz.com:8080/@https://xyz.com/@)}**

}

# Enable the stream filter for this response only

STREAM::enable

}

I have highlighted additional changes for other url. You can compare both iRules to get clarity. This way you can have multiple re-directions for multiple URLs under same iRule.

Thank you,

Mayur

---

<div class="post-metadata">

**Author:** ![VikashC](https://avatars.discourse-cdn.com/v4/letter/v/5f8ce5/32.png) [@VikashC](https://community.f5.com/u/VikashC)\
**Post date:** [April 13, 2020, 3:15am UTC](https://community.f5.com/t/need-irule-for-redirection-for-port-translation/48772/6 "2020-04-13T03:15:13Z")

</div>

Okay, got it.
