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 anyone help with this one too?
TCL error: more_redirects HTTP_REQUEST -
cant read my_uri: no such variable while executing
HTTP::redirect http://legacy.site.com$my_uri
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] equals "/url1" or [string tolower [HTTP::uri]] equals "/url1/" } {
HTTP::redirect "http://somesite.com/url2/"
}
set my_uri [string tolower [HTTP::uri]]
if { $my_uri starts_with "/images" } {
redirect to legacy.somesite.com/images on matching URI
HTTP::redirect http://legacy.somesite.com$my_uri
}
if { ([HTTP::host] eq "www.somesite.com") } {
switch -glob [HTTP::uri] {
"/" { HTTP::redirect "http://somesite.com" }
default { HTTP::redirect "http://somesite.com[HTTP::uri]" }
}
}
}
- Joe_Pipitone
Nimbostratus
This has been semi resolved using a default statement. - Michael_Yates
Nimbostratus
From 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]).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]" } }
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]" } } }
- Joe_Pipitone
Nimbostratus
Hi guys - here's an update.when HTTP_REQUEST { if { [HTTP::host] equals "www.oursite.com" } { HTTP::redirect "http://oursite.com" } switch -glob [ string tolower [HTTP::uri]] { "/survey" - "/survey/" { HTTP::redirect "http://[HTTP::host]/surveys/" } "/images*" { HTTP::redirect "http://legacy.oursite.com[HTTP::uri]" } } }
- Joe_Pipitone
Nimbostratus
I've been able to use an answer from another post to fix this issue. I appreciate your time and effort in helping me get this resolved - it is greatly appreciated! It seemed to have worked by using this code:when HTTP_REQUEST { if { ([HTTP::host] eq "www.oursite.com") } { HTTP::redirect "http://oursite.com[HTTP::uri]" return } switch -glob [string tolower [HTTP::uri]] { "/survey" - "/survey/" { HTTP::redirect "http://oursite.com/surveys/" return } "/salarysurveys" { HTTP::redirect "http://oursite.com/surveys/" return } "/images*" { HTTP::redirect "http://legacy.oursite.com[HTTP::uri]" return } } }
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