Forum Discussion
Keith_Goguen_52
Nimbostratus
Apr 06, 2011Simple 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.
21 Replies
- Michael_Yates
Nimbostratus
This is a simple version that will do the initial redirect.when HTTP_REQUEST { if { [HTTP::path] equals "/" } { HTTP::redirect "/somewhere/else.html" } }
Let us know if this takes care of what you need or if you need anything else. - Keith_Goguen_52
Nimbostratus
Most Excellent!!! Worked like a charm. Thanks. - Michael_Yates
Nimbostratus
This 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" } }
If you are needing something in addition to this or different functionality let us know. - Arie
Altostratus
Keep 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_78747
Nimbostratus
I 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.
Not sure if "*" is the correct wildcard in TCL scripting, but when I put in "*", I actually mean that user could be puting different value.
Thanks
Roger - 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]" } }
Colin - rogerluo_78747
Nimbostratus
yes, this is what I put in right now:
when HTTP_REQUEST {
if {[HTTP::path] matches_regex "/*"} {
HTTP::redirect "/aaa/bbb[HTTP::uri]"
}
}
I did a packet capture on the VIP and by follow TCP stream, I find this iRule will insert /aaa/bbb with every HTTP request dose not matter it have /aaa/bbb or not. It will just insert /aaa/bbb over and over without stop, so the HTTP GET becomes....
1. GET /aaa/bbb/test.html
2. GET /aaa/bbb/aaa/bbb/test.html
3. GET /aaa/bbb/aaa/bbb/aaa/bbb/test.html
............
............
n. GET /aaa/bbb/aaa/bbb/...................................../aaa/bbb/aaa/bbb/test.html
Is there anything I can do in this iRule to make it insert only once?
Thanks
Roger - 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")} {
This means that the redirect only occurs if the URI doesn't already start with "/aaa/bbb"
Colin - Colin_Walker_12Historic F5 AccountI'm glad you got it working. :)
Colin - Bayan_El_Ameen1
Nimbostratus
Hey guys,
This iRule works perfectly for me:when HTTP_REQUEST { if { [HTTP::path] equals "/" } { HTTP::redirect "/apath" } }
But before using it I tried the following and it didn't work but I still have the curiosity to know why if anyone has any idea why please let me know. Here's my iRule:when HTTP_REQUEST { set val [HTTP::uri] if { {[string length $val] == 0} or {[string length $val] == 1} } { HTTP::redirect https://[HTTP::host]/apath } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
