Forum Discussion
iRule, Traffic Policy or Re-Write Policy
- Sep 24, 2025
you may see https://hostnameA.test.com:666 in the browser for many reasons
thats why I am asking if there is a redirect response (301 or 302) or there is something else
anyway give this a trywhen HTTP_REQUEST { STREAM::disable HTTP::header remove "Accept-Encoding" if {[IP::addr [IP::client_addr] equals 192.168.1.1] } { pool POOL_A set selected_hostname "hostnameA.test.com" HTTP::header replace Host $selected_hostname } elseif {[IP::addr [IP::client_addr] equals 192.168.2.1] } { pool POOL_B set selected_hostname "hostnameB.test.com" HTTP::header replace Host $selected_hostname } elseif {[IP::addr [IP::client_addr] equals 192.168.3.1] } { pool POOL_C set selected_hostname "hostnameC.test.com" HTTP::header replace Host $selected_hostname } } when HTTP_RESPONSE { if {[HTTP::header exists "Location"] && [info exists selected_hostname]} { set loc [HTTP::header "Location"] if {[string match "https://$selected_hostname:666*" $loc]} { HTTP::header replace "Location" [string map "https://$selected_hostname:666 https://example.com" $loc] } } if {[HTTP::header "Content-Type"] contains "text" && [info exists selected_hostname]} { STREAM::expression "@https://$selected_hostname@https://example.com@" STREAM::enable } }
Thank you for the irule. I've only just been able to get back to this project due to other work.
when HTTP_REQUEST
{
STREAM::disable
HTTP::header remove "Accept-Encoding"
set original_uri [HTTP::uri]
HTTP::uri "/test${original_uri}"
}
Apologises for my understanding of this but my iRules knowledge is basic
So when there is an HTTP request
set original_uri [HTTP::uri] >> set the original_uri means keep the original uri and store it as a variable? This would be https://example.com
HTTP::uri "/test${original_uri}" } >> this is the replacement, so the $ gets the variable and appends the test to it https://example.com/test
Is it possible to make the following happen?
https://example.com to https://different.name.com:666
{
STREAM::disable
HTTP::header remove "Accept-Encoding"
set original_uri [HTTP::uri]
HTTP::uri "https://different.name.com:666"
}
Within the response, do I just substitute in as follows
when HTTP_RESPONSE
{
if {[string match "https://different.name.com:666*" $loc]}
HTTP::header replace "Location" [string map {"https://different.name.com:666" "https://example.com"} $loc]
Would the stream profile be like this?
Thanks
Hi sjy2025
So when there is an HTTP request
set original_uri [HTTP::uri] >> set the original_uri means keep the original uri and store it as a variable? This would be https://example.com
HTTP::uri "/test${original_uri}" } >> this is the replacement, so the $ gets the variable and appends the test to it https://example.com/test
that's correct
Is it possible to make the following happen?
in this case, different.name.com is the host not the uri
if understand correct you want client request https://example.com but you send to the server https://different.name.com:666
Fisrtly you have to define the port in pool itslelf, so just create a pool with the ip of the server and port 666. Suppose you name the pool 666_pool
then you can use below irule as an example
when HTTP_REQUEST
{
if { ([string tolower [HTTP::host]] equals "example.com") }
{
HTTP::header replace Host "different.name.com"
pool 666_pool
}
}
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com