Forum Discussion
Joe_Pipitone
Nimbostratus
May 12, 2010More conflicts with redirect iRule
I am getting the following error with the iRule below. Something about no such variable when executing. Perhaps this is because there is no URI sometimes if the user requests the homepage? Can anyo...
Michael_Yates
Nimbostratus
May 13, 2010From what you are trying to do with your iRule, you shouldn't need to put the [HTTP::uri] or [HTTP::path] into a variable unless you are doing something else that you didn't include in your post. The F5 is already doing that for you with these two iRule Variables ([HTTP::uri] and/or [HTTP::path]).
Try this and see if it works better for you:
- I didn't include the target="_blank", so you can add that back in if you want the redirect to open in a new browser.
when HTTP_REQUEST {
if { [HTTP::host] equals "www.somesite.com" } {
HTTP::redirect "http://somedifferentsite.com"
}
if { [ string tolower [HTTP::uri]] equals "/url1" or [ string tolower [HTTP::uri]] equals "/url2" } {
HTTP::redirect "http://[HTTP::host]/url2"
}
elseif { [ string tolower [HTTP::uri]] starts_with "/images" } {
HTTP::redirect "http://legacy.somesite.com[HTTP::uri]"
}
}
You could also do it this way:
when HTTP_REQUEST {
if { [HTTP::host] equals "www.somesite.com" } {
HTTP::redirect "http://somedifferentsite.com"
}
switch -glob [ string tolower [HTTP::uri]] {
"/url1*" -
"/url2*" { HTTP::redirect "http://[HTTP::host]/url2" }
"/images*" { HTTP::redirect "http://legacy.somesite.com[HTTP::uri]" }
}
}
The dash on the end of the ( "/url1*" - ) statement tells it to follow the same action as the next statement, so in this case it will follow the same action as the "/url2*".
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