Forum Discussion
Keith_Goguen_52
Apr 06, 2011Nimbostratus
Simple iRule for URL appending?
Hey - was wondering if someone could give me a hand with a pretty basic task... how to append(or redirect) and URL. I have some people comming into a VS for "host.unit.com", but I have to send them to "host.unit.com/somewhere/else". The VS is taking in HTTP port 80, but is doing PAT to different nodes on different ports. I tried a couple of iRule examples, but failed. Anything would be appreciated... thanks.
- Michael_YatesNimbostratusThis is a simple version that will do the initial redirect.
when HTTP_REQUEST { if { [HTTP::path] equals "/" } { HTTP::redirect "/somewhere/else.html" } }
- Keith_Goguen_52NimbostratusMost Excellent!!! Worked like a charm. Thanks.
- Michael_YatesNimbostratusThis is a simple version that does what you are describing that you need.
when HTTP_REQUEST { if { [HTTP::path] equals "/" } { HTTP::redirect "/somewhere/else.html" } }
- ArieAltostratusKeep in mind that HTTP::redirect issues a 302 - temporary redirect. It's more efficient to use 301s (permanent redirect) since it's cached by the client.
If you're pretty certain that the redirect target is not likely to change I'd use a 301. Otherwise you'll want to stick with a 302.
- rogerluo_78747NimbostratusI have an very similar request which is that instead of append uri after url, I need insert "/aaa/bbb" in between. e.g. when user type in "http://www.testdomain.com/*", my F5 iRule need insert /aaa/bbb/ and make it "http://www.testdomain.com/aaa/bbb/*". Looking forward your kindly reply.
- Colin_Walker_12Historic F5 AccountThen you'd want something like:
when HTTP_REQUEST { if {!([HTTP::uri] starts_with "/aaa/bbb")} { HTTP::redirect "http://www.testdomain.com/aaa/bbb[HTTP::uri]" } }
- rogerluo_78747Nimbostratusyes, this is what I put in right now:
- Colin_Walker_12Historic F5 AccountThe rule I wrote earlier does that check. The line that's important is:
if {!([HTTP::uri] starts_with "/aaa/bbb")} {
- Colin_Walker_12Historic F5 AccountI'm glad you got it working. :)
- Bayan_El_Ameen1NimbostratusHey guys,
when HTTP_REQUEST { if { [HTTP::path] equals "/" } { HTTP::redirect "/apath" } }
when HTTP_REQUEST { set val [HTTP::uri] if { {[string length $val] == 0} or {[string length $val] == 1} } { HTTP::redirect https://[HTTP::host]/apath } }
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