Forum Discussion
Shivam_84461
Nimbostratus
May 21, 2015Problem with URL redirection
I wanted to redirect the webpages on this condition
if http://xyz.com/j/k/l
redirect to www.abc.com
if http://xyz.com
redirect to https://xyz.com/a/b
When I configured the irule, first part is ...
Michael_Yates
Nimbostratus
May 21, 2015Hi Shivam,
You have several options:
Using a Switch Statement (useful to start if you are going to be adding a lot of URI specific behavior):
when HTTP_REQUEST {
switch -glob [ string tolower [HTTP::uri]] {
"/j/k/l" { HTTP::redirect "http://www.abc.com" }
"/" { HTTP::redirect "https://xyz.com/a/b" }
default {
if { [TCP::local_port] != 443 } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
}
}
}
Or using a bunch of IF Statements (which is faster than a small SWITCH Statement (until you get above 4 or 5 IF Statements, then a SWITCH Statement is more efficient)).
when HTTP_REQUEST {
if { [ string tolower [HTTP::uri]] equals "/j/k/l" } {
HTTP::redirect "http://www.abc.com"
}
if { [ string tolower [HTTP::uri]] equals"/" } {
HTTP::redirect "https://xyz.com/a/b"
}
if { [TCP::local_port] != 443 } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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