Forum Discussion
Dynamic redirect
Hi, I am a newbie to irule and can only do basic redirect. But we have a requirement for dynamic redirect. Can someone help?
http://www.abc.com/test/[placeholder]
permanent redirect to
http://abc.123.net/dc?purl=[placeholder]
For example:
http://www.abc.com/test/abc should be redirected to
http://abc.123.net/dc?purl=abc
Thanks
5 Replies
- nitass
Employee
[root@tulip:Active] config b virtual bar list virtual bar { destination 172.28.17.66:http ip protocol tcp rules myrule profiles http tcp } [root@tulip:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { HTTP::redirect "http://abc.123.net/dc?purl=[string range [HTTP::uri] 6 end]" } } [root@tulip:Active] config curl -I http://www.abc.com/test/abc HTTP/1.0 302 Found Location: http://abc.123.net/dc?purl=abc Server: BigIP Connection: Keep-Alive Content-Length: 0 - kupaloid_50119
Nimbostratus
Thanks Nitass for the quick reply. I need to match http://www.abc.com/test/ since several irules are applied on the vip. What should be my match statement?rule myrule {
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/test"} {
HTTP::redirect "http://abc.123.net/dc?purl=[string range [HTTP::uri] 6 end]" }
}
}
- nitass
Employee
that's fine.[root@tulip:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with "/test"} { HTTP::redirect "http://abc.123.net/dc?purl=[string range [HTTP::uri] 6 end]" } } } [root@tulip:Active] config curl -I http://www.abc.com/aaaaaa/bbbbb/cccccc curl: (52) Empty reply from server [root@tulip:Active] config curl -I http://www.abc.com/test/abc HTTP/1.0 302 Found Location: http://abc.123.net/dc?purl=abc Server: BigIP Connection: Keep-Alive Content-Length: 0 - nitass
Employee
or if u wanna match host name as well.rule myrule { when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "www.abc.com" and [string tolower [HTTP::uri]] starts_with "/test"} { HTTP::redirect "http://abc.123.net/dc?purl=[string range [HTTP::uri] 6 end]" } } } - kupaloid_50119
Nimbostratus
cool thanks
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
