# iRule or Re-write Profile

**URL:** <https://community.f5.com/t/irule-or-re-write-profile/76374>\
**Category:** Technical Forums\
**Tags:** irules, rewrite\
**Created:** [July 22, 2025, 2:54pm UTC](https://community.f5.com/t/irule-or-re-write-profile/76374 "2025-07-22T14:54:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjy2025](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/sjy2025/32/5847_2.png) [@sjy2025](https://community.f5.com/u/sjy2025)\
**Post date:** [July 22, 2025, 2:54pm UTC](https://community.f5.com/t/irule-or-re-write-profile/76374/1 "2025-07-22T14:54:43Z")

</div>

I’m trying to work out how to do the following.

I have an irule that is directing source traffic (based on IP) to a specific pool

I have a rewrite policy \> changing [https://example.com](https://example.com) to [https://example.com/text](https://example.com/text)

this is all working

The problem I have, is I’d like [https://example.com](https://example.com) to stay the same in the client’s browser

But after the client connects to the backend servers, they return a uri [https://host1.com](https://host1.com)

I’d like that to appear as [https://example.com](https://example.com)

I looked at my rewrite policy and was thinking I could do a response

 ![image_342648.png](https://d20hrnpixdzcsd.cloudfront.net/original/3X/3/5/35c9d862170f92f7e7f4264ef6c3b44b2b42b226.png)

This doesn’t appear to work.

Should I be using a single iRule to

Replace the name (inbound)

Direct to a pool

Replace the name (outbound)

---

<div class="post-metadata">

**Author:** ![Sravs](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Sravs](https://community.f5.com/u/Sravs)\
**Post date:** [July 23, 2025, 8:35am UTC](https://community.f5.com/t/irule-or-re-write-profile/76374/2 "2025-07-23T08:35:54Z")

</div>

Yes, you can try following rule.

when HTTP\_REQUEST {  
&nbsp; &nbsp; if { [IP::client\_addr] eq “x.x.x.x” } {  
&nbsp; &nbsp; &nbsp; &nbsp; pool pool\_A  
&nbsp; &nbsp; }  
&nbsp; &nbsp; HTTP::header replace “Host” “[host1.com](http://host1.com)”  
}

when HTTP\_RESPONSE {  
&nbsp; &nbsp; if { [HTTP::header exists “Location”] } {  
&nbsp; &nbsp; &nbsp; &nbsp; set location [HTTP::header “Location”]  
&nbsp; &nbsp; &nbsp; &nbsp; set updated\_location [string map {“[host1.com](http://host1.com)” “[example.com](http://example.com)”} $location]  
&nbsp; &nbsp; &nbsp; &nbsp; HTTP::header replace “Location” $updated\_location  
&nbsp; &nbsp; }

# Optional: content replacement if backend returns HTML with embedded URLs  
&nbsp; &nbsp; if { [HTTP::header “Content-Type”] contains “text/html” } {  
&nbsp; &nbsp; &nbsp; &nbsp; STREAM::enable  
&nbsp; &nbsp; }  
}

when STREAM\_MATCHED {  
&nbsp; &nbsp; STREAM::replace “[host1.com](http://host1.com)” “[example.com](http://example.com)”  
}

when HTTP\_RESPONSE\_DATA {  
&nbsp; &nbsp; # Needed for stream profile  
}

please try above irule.

---

<div class="post-metadata">

**Author:** ![Injeyan\_Kostas](https://d1p9zq3aats0t8.cloudfront.net/user_avatar/community.f5.com/injeyan_kostas/32/263_2.png) [@Injeyan\_Kostas](https://community.f5.com/u/Injeyan_Kostas)\
**Post date:** [July 23, 2025, 10:09am UTC](https://community.f5.com/t/irule-or-re-write-profile/76374/3 "2025-07-23T10:09:28Z")

</div>

Hi @sjy2025

you have open a similar topic  
[iRule, Traffic Policy or Re-Write Policy | DevCentral](https://community.f5.com/post/342650)

check my answer there.
