Forum Discussion
Help with irules redirect
Thanks in advance. The first irule works but the last one with the / appears not to be working and I was told that I need a uri. Can you please examine and let me know if the most effiecient way of doing the Irule
Here is the irule:
when HTTP_REQUEST {
log local0. "Requested hostname is: [HTTP::host]"
switch -glob [string tolower [HTTP::host]] {
"*mywebsite1*" {
HTTP::respond 302 Location ""
}
"*mywebsite3.website.com/public*" {
HTTP::respond 302 Location "http://mywebsite4.com/public"
}
default { pool Web_Servers }
}
}
Thanks,
Michael
3 Replies
- Brian_69413
Nimbostratus
You are switching on the incoming host, not the URI, so you will never match "*mywebsite3.website.com/public*" you could match on "*mywebsite3.website.com" though. you do not want '*' at the end of the host options. - newmedia_129255
Nimbostratus
Hi Brian, what I"m looking for is when the users types mywebsite.website.com/public I want to do a 302 redirect to http://mywebsite.website4.com/public and when they type & mywebsite.website.com/public2 I want to do a 302 redirect to http://mywebsite.website4.com/public2. Will this syntax work:
"*mywebsite.website.com*" {
if { ([string tolower [HTTP::uri]] contains "public") } {
HTTP::respond 302 Location "http://mywebsite.website4.com/public" }
elseif { ([string tolower [HTTP::uri]] contains "public2") } {
HTTP::respond 302 Location "http://mywebsite.website4.com/pubilc2" } } - bwolmarans_1284Historic F5 AccountHi NewMedia,
I don't have much time to reply, so this is "sub-optimal" as they say but this will work:
when HTTP_REQUEST {
log local0. "Requested uri is: [HTTP::uri] "
if { [string tolower [HTTP::uri]] starts_with "/public2" } {
HTTP::respond 302 Location "http://mywebsite.website4.com/public2"
} elseif { [string tolower [HTTP::uri]] starts_with "/public" } {
HTTP::respond 302 Location "http://mywebsite.website4.com/pubilc"
} else {
pool Web_Servers
}
}
There is a better way, I'm sure, but I don't have time right now. But that will work for now.
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