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]" }
}
}
}4 Replies
- 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]).
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*". - Joe_Pipitone
Nimbostratus
Hi guys - here's an update.
I'm trying to use the following code that you've provided above. (I've modified it again to hide our real URLs) Note I've added a survey and a survey/ with a trailing / as our CMS application automatically appends an .aspx unless we do so. I tried to make this as clear as possible - thanks for your help so far.
This partially works:
- If I go to http://www.oursite.com/survey or http://www.oursite.com/survey/, I get redirected to our homepage (http://oursite.com/Home.aspx)
- If I go to http://oursite.com/survey or http://oursite.com/survey/, I get redirected properly.
- It doesn't seem to want to rewrite properly without the www if I go to http://www.oursite.com/surveys/ either, however I see the proper page.
- If I go to http://www.oursite.com/images, I get a "The connection was reset" in my browser.
- If I go to http://oursite.com/images, I get redirected properly.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
