Forum Discussion
whootang
Nimbostratus
Nov 03, 2019irule to redirect and rewrite url
Hi guys,
I'm playing around with irules and im trying to do some smarts around a base url redirect and then a rewrite on sub folders.
So if you hit testdata.com it will redirect you to xyz.com
but if you hit testdata.com/data/* it will rewrite to abc.com/data/*
i cant seem to get it working. any pointers will be awesome.
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/" } {
HTTP::redirect "https://xyz.com/"
}
if { [string tolower [HTTP::uri]] starts_with "/data/*" } {
HTTP::redirect "http://abc.com/data/*"
}
}
Hi whootang,
If you use starts_with for "/", second "if" will never work.
when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { HTTP::redirect "https://xyz.com/" } if { [string tolower [HTTP::uri]] starts_with "/data/" } { HTTP::redirect "http://abc.com[HTTP::uri]" } }
Alternative:
when HTTP_REQUEST { if { [HTTP::host] equals "testdata.com" } { switch -glob [string tolower [HTTP::uri]] { "/" { HTTP::redirect "https://xyz.com/" } "/data/*" { HTTP::redirect "http://abc.com[HTTP::uri]" } } } }
- whootang
Nimbostratus
Great eaa let me test this bad boy out, thanks for taking the time to reply :)
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects