Forum Discussion
URL rewrite through iRule
Hi Guys, i have one "Performance (HTTP)" virtual server on F5-1600 series, and i want to change the URL "http://www.abc.com" to "http://partner.abc.com/xyz". i have tried all below scripts :
1- when HTTP_REQUEST { if {([string tolower [HTTP::host]] equals "http://www.abc.com")}{ HTTP::header replace Host "http://partner.abc.com/xyz" } }
2- when HTTP_REQUEST { if { not ([HTTP::uri] starts_with "/xyz") } { HTTP::uri /xyz[HTTP::uri] } }
3- when HTTP_REQUEST { if {[HTTP::uri] equals {http://www.abc.com}} {HTTP::uri {http://partner.abc.com/xyz} } }
but i wasn't successful! can anyone help me how can i do this through iRule ?
Hi Sunnyman,
This will work;
if { [IP::addr [IP::client_addr] equals 1.1.1.1] || [IP::addr [IP::client_addr] equals 1.1.1.2} { SNAT with 1.1.1.100 snatpool VM_SNAT_POOL_1_1_1_100 } elseif { [IP::addr [IP::client_addr] equals 1.1.1.11] || [IP::addr [IP::client_addr] equals 1.1.1.12} { SNAT with 1.1.1.100 snatpool VM_SNAT_POOL_1_1_1_200 }
But that's not a very scalable way of doing it if your list is going to grow. If it's going to grow then use an address datagroup, with values snatpool names, which you can use like this
snatpool [class match -value [IP::remote_addr] equals dg_sunnyman_snatpools]
or more correctly;
set snatpool [class match -value [IP::remote_addr] equals dg_sunnyman_snatpools] if {$snatpool ne "") { snatpool $snatpool }
- sunnyman67_1367Nimbostratus
Hi Joanna Thanks a lot for your solution, when i changed the the virtual server type to "Standard" and add "HTTP Profile", it works fine! But now i have another issue: now i want to do URL-rewrite to another port number on another server. For example when clinets want to see "abc.com/ukm", i want to change it to "1.1.1.1:8080/xyz". I've checked it with below script, but i didn't work. Am i wrong?
if {[string tolower [HTTP::host]] starts_with "abc.com" && [string tolower [HTTP::path]] eq "/ukm"} { HTTP::header replace Host "1.1.1.1:8080" HTTP::uri "/xyz" }
- IheartF5_45022Nacreous
Hi - Yes you were very close to the correct solution in the first place.
You need to change to "Standard" virtual server and apply an HTTP profile (and a oneconnect profile if you are using layer7 persistence, like 'cookie'). If you have any problems then delete and then recreate the virtual server.
- sunnyman67_1367Nimbostratus
Hi Joanna, Thanks a lot, I think your solution is almost the same of my first solution, but it's better to check it with yours. Meanwhile, i have one another problem: if i want to use "HTTP::Host" part of script on "Performance (HTTP)" virtual server mode, F5 tells me to use "HTTP Profile", but when i use "Standard" type of virtual server, F5 can not load balances the web traffic. So i should to use "Performance (HTTP)" mode. In this situation, is there any solution to do that through "Performance (HTTP)" mode? Thanks and Regards Joanna...
- IheartF5_45022Nacreous
Hi this is the code you need in HTTP_REQUEST;-
if {[string tolower [HTTP::Host]] starts_with "www.abc.com" && [HTTP::path] eq "/"} { HTTP::header replace Host "partner.abc.com" HTTP::uri "/xyz" }
In addition, you may need to remove the Performance HTTP profile as it only gives you v limited l7 iRule support.
Jo
- sunnyman67_1367Nimbostratus
Meanwhile, i want to do that without any redirection, i just want to rewrite the url, thanks all...
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