Forum Discussion
BigIP_Support_9
Nimbostratus
Feb 23, 2006Change URI without redirect
I want to change the user URI as below:
http://www.abc.com/demo -> http://www.abc.com/demo1
Here is my code:
if (http_uri == "/demo") {
redirect to "http://" + http_host + "/demo1/"
}
else {
if (http_uri matches_regex "/demo/") {
redirect to "http://" + http_host + "/demo1/" + substr(http_uri, 6, 1000)
}
else {
use pool demo-pool
}
}
It works but it requires too many redirect. Clients are required to use new conenction after redirect according
to RFC 2616.
In fact I just want to change demo to demo1. Can I change the URI and forward to demo-pool pool within a single "if" clause? I don't want to redirect and client go back again and falls to the last "if" clause.
5 Replies
- Colin_Walker_12Historic F5 AccountIt looks like you just need to work on your logic a little. Your second if clause would grab a lot of the same URIs as the first one, unless there's been something added to the "demo" in the uri.
I'd recommend changing the logic of the second if clause to be a little more specific in looking for a uri that has demo as well as something else, so that users won't end up getting redirected twice.
As it stands right now, the user comes in with a URI of "demo", gets redirected to "demo1" then gets redirected again because that still matches the regex in the second if clause.
-Colin - BigIP_Support_9
Nimbostratus
The first if-clause is to capture http://www.abc.com/demo
The secondd if-clause is to capture http://www.abc.com/demo/ or http://www.abc.com/demo/xx/yy.html etc
I will get redirect one time only no matter which case it is. However we don't want that redirect because it is redirect back to bigip itself. It would be much more efficient to change the URI and forward to a pool immediately, rather than get back the redirect to client and client initiate a new request to match the last else-clause. - BigIP_Support_9
Nimbostratus
I searched and see that in v9.x iRules, we can do below, so we don't need to use REDIRECT to just to change the URI but still forward to same FQDN, same server poolif (http::uri equals "/demo") { HTTP::uri "http://" + http_host + "/demo1/" pool demo-pool } else { if (http::uri contains "/demo/") { HTTP::uri "http://" + http_host + "/demo1/" + substr(http_uri, 6, 1000) pool demo-pool } else { pool demo-pool } }
How can I do above in v4.x? - Martin_MachacekHistoric F5 AccountThere is no way how to achieve what you want in v4.x. v9.x iRules are much more powerful.
- chief_rocka_334
Nimbostratus
I needed the same type of iRule and this worked for me with no redirects.
when HTTP_REQUEST { if { [string tolower [HTTP::path]] starts_with "/demo/" } { HTTP::path [string map {"/demo/" "/demo1/"} [HTTP::path]] } else{ pool demo-pool } }
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
