Forum Discussion
iRule redirection with URI caveat
Hi DevCentral. iRule noob here, trying to tackle what I think is probably a very simple request. There's two parts, the first of which should allow anything to https://.../exshortcut to go through. The second, anything else coming in on port 80 or 443, will go to https://.../search. I've cobbled together the following, but the redirect doesn't seem to execute when coming in on 443:
when HTTP_REQUEST {
if { ([HTTP::uri] starts_with "/exshortcut") } {
HTTP::uri "[HTTP::uri]"
}
else {
HTTP::redirect "https://10.110.66.34/search"
}
}
Is there anything simple I'm overlooking? Also, if I do get the redirect to /search working, will it break functionality for all other URIs after the initial redirect? For instance, if I get a successful redirect to https://10.110.66.34/search and try to head on over to https://10.110.66.34/search/abc123, will I be looped right back to /search? Any feedback is appreciated. Thanks, all!
- Lee_Sutcliffe
Nacreous
Hi Mike,
Could you tell me what port your virtual server is configured to use? Typically you'd have two virtual servers, one on TCP/80 and the other on TCP/443, That way you're explicit which ports are permitted.
A simple iRule like the one below will redirect anything that does NOT start with /exshortcut. If the URI does start with exshortcut, it will be allowed implicitly
when HTTP_REQUEST { if {!([HTTP::uri] starts_with "/exshortcut")} { HTTP::redirect "https://10.110.66.34/search" } }
This could also be completed using an LTM traffic policy
To answer your question about the redirect, yes if the IP address specified is that of the VS that the iRule is attached to, you will get caught in a loop. If you do not need to redirect, you could rewrite the using HTTP::uri, in order to do so you'd need to know what subsequent URIs would look like so that it is re-written correctly.
If still going down th redirect route, the following example will only redirect if the URI does not already start with /search
when HTTP_REQUEST { if {!([HTTP::uri] starts_with "/exshortcut")} { if {!([HTTP::uri] starts_with "/search")} { HTTP::redirect "https://10.110.66.34/search" } } }
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