Forum Discussion
Replacing the beginning of the URI if entire URI is not explicitly allowed
New to the forum and may have bitten off more than I can chew for a newbie.
I need to create an iRule that meets the following criteria:
if HOST = "www.domain.com" AND URI starts with "/subdirectory" AND the complete URI does not equal either "/subdirectory/checkout.aspx" or "/subdirectory/orderhistory.aspx" THEN URI equals "/newplace" & remaining URI
Essentially if the domain name is true, the URI starts with /subdirectory, and is NOT either of the two specific files listed, then to replace the start of the URI to be /newplace. The intent being to push all traffic into /newplace unless one of two exceptions.
Below is what I have come up with
set STAYURI {"/checkout.aspx" "/orderhistory.aspx"}
set CHECKURI {"/subdirectory"}
if { [HTTP::host] equals "www.domain.com" } {
if {[string tolower [HTTP::uri]] starts_with CHECKURI } {
if {[string tolower [HTTP::uri]] not equals foreach x concat $CHECKURI $STAYURI } {
HTTP::uri "/newplace[string range $uri 13 end]"
}
}
am I close to achieving my objective?
2 Replies
- dgeorgeson_2230
Nimbostratus
I simplified things a bit which I believe still meets my objective. Since I have a small list of specific URI to not redirect, I rewrote the irule thusset STAYURI {"/subdirectory/checkout.aspx" "/subdirectory/orderhistory.aspx"} if { [HTTP::host] equals "www.domain.com" } { if {foreach x $STAYURI { [string tolower [HTTP::uri]] not equals x} { HTTP::uri "/newplace[string range $uri 13 end]" } } - The_Bhattman
Nimbostratus
Hi Dgeorgeson,
I think the following untested iRule will be a bit more efficient
when HTTP_REQUEST {
set hostn [HTTP::host]
set basen [URI::basename[HTTP::uri]]
set uri [string tolower [HTTP::uri]]
if {($hostn eq "www.domain.com") and ( $uri starts_with "/subdirectory") } {
if { !(($basen eq "checkout.aspx" ) or ($basen eq "orderhistory.aspx")) } {
HTTP::uri "/newplace/$basen"
}
}
}
I hope this helps
Bhattman
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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