Forum Discussion

UWK-87_372210's avatar
UWK-87_372210
Icon for Nimbostratus rankNimbostratus
Sep 18, 2018

iRule that can change certain URL for all the values in STREAM/FUNCTION CALLS/SCRIPTS

Hi,

I am a newbie at F5 iRule, with no experience with HTML/website coding and will really appreciate your help with this issue.

We have a website which is replication of a production website. So the team does not want to change any code on this website and have F5 change STREAM values so that the internal links are pointing towards a non-prod/testing services (so when they are done testing they can just overwrite the production website).

When we open the replicated website which is at , we should change the following URL in stream, scripts, functions etc. (I hope that I am using correct terms):

 

s1.mydomain.com
s2.mydomain.com
s3.mydomain.com
s4.mydomain.com
s5.mydomain.com

 

change them to the following:

 

s1.mytest.local
s2.mytest.local
s3.mytest.local
s4.mytest.local
s5.mytest.local

 

The iRule that I have configured is as below:

 

when HTTP_REQUEST 
{
STREAM::disable
HTTP::header remove "Accept-Encoding"
}

when HTTP_RESPONSE 
{

    if { [HTTP::header value Content-Type] contains "text"}
    {
        STREAM::expression {&s1.mydomain.com&& &s2.mydomain.com&& &s3.mydomain.com&& &s4.mydomain.com&& &s5.mydomain.com&&}
        STREAM::enable
    } 
}
when STREAM_MATCHED 
{
   set tmp1 [string map [list "mydomain.com" "mytest.local"] [STREAM::match]]
   set finaltmp [string map [list "http://" "https://"] ${tmp1}] 
   STREAM::replace ${finaltmp}
}

 

So what I see in the F12 developer mode of the webpage is mixed output of both mydomain.com & mytest.local . I can see there are different type for e.g. script, xhr, font etc and not all of them are processed with the STREAM rule.

I opened the replicated website with the iRULE in place and copied an example of two requests one which was changed because of the iRULE and the other which had no affect. I copied these two to excel and pasting hem below for your reference:

Can you kindly guide me on how I can make sure every mention mydomain.com is changed to mytest.local be it in script, xhr or be it called as a aspx function?