Forum Discussion
vidya_126776
Nimbostratus
Mar 05, 2013issue with irule script ???
This one works fine.
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] contains "/secure_one" } {
set replaceURI [string map [list /secure /wrap1] [HTTP::uri]]
HTTP::redirect "$replaceURI"
}
elseif { [HTTP::uri] contains "/one" } {
HTTP::redirect "" }
}
But the following doesn't work fine. why ?
when HTTP_REQUEST {
if {{ [string tolower [HTTP::uri]] contains "/secure_one" } {
set replaceURI [string map [list /secure_one /wrap1] [HTTP::uri]]
HTTP::redirect "$replaceURI"
}
elseif { [HTTP::uri] contains "/one" } {
HTTP::redirect "http://www111.abc.com[HTTP::uri]" }
}
if {{ [string tolower [HTTP::uri]] contains "/ask_wrap" } {
set replaceURI [string map [list /ask_wrap /wrap1] [HTTP::uri]]
HTTP::redirect "$replaceURI"
}
elseif { [HTTP::uri] contains "/wrap" } {
HTTP::redirect "http://www111.abc.com[HTTP::uri]" }
}
if {{ [string tolower [HTTP::uri]] contains "/seek_pond" } {
set replaceURI [string map [list /pond /wrap1] [HTTP::uri]]
HTTP::redirect "$replaceURI"
}
elseif { [HTTP::uri] contains "/seek" } {
HTTP::redirect "http://www111.abc.com[HTTP::uri]" }
}}
no luck with this... have been trying for sometime....
6 Replies
- What_Lies_Bene1
Cirrostratus
You seem to have too many braces in there with each if statement (two instead of one) and I would also suggest you put a line break between the last two as well. Note you could improve the rule by only having the first if and everything else being an elseif. Also, I'd say using the string operator would be far better than using this many if, elseif statements. This doesn't quite cover all your requirements but gives you the idea;when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/wrap*" - "/seek*" - "/one*" { HTTP::redirect "http://www111.abc.com[HTTP::uri]" } "/secure_one*" - "/seek_pond*" - "/ask_wrap*" { HTTP::redirect "$replaceURI" } } } - vidya_126776
Nimbostratus
Hi
Thanks for the reply, just want to clarify the requirement.
when we try for any of the URL, a part of URI needs to be changed to wrap1 and rest of the URI should be same. pls note this has both URL redirection with URI parsing too.
http://www111.abc.com/secure_one/anythinghere/image.gif
http://www111.abc.com/ask_wrap/anythinghere/anythinghere/image.gif
http://www111.abc.com/seek_pond/anythinghere/anythinghere/image.gif
should redirect to
http://www245.abc.com/wrap1/rest of old uri - What_Lies_Bene1
Cirrostratus
I'm sure it could be improved but for now this will do and is still far better;when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/wrap*" - "/seek*" - "/one*" { HTTP::redirect "http://www111.abc.com[HTTP::uri]" } "/secure_one*" { set replaceURI [string map [list /secure_one /wrap1] [HTTP::uri]] HTTP::redirect "$replaceURI" "/seek_pond*" { HTTP::redirect "$replaceURI" set replaceURI [string map [list /seek_pond /wrap1] [HTTP::uri]] "/ask_wrap*" { set replaceURI [string map [list /ask_wrap /wrap1] [HTTP::uri]] HTTP::redirect "$replaceURI" } } } - nitass
Employee
just another example.[root@ve10:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.19.252:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { if { [HTTP::host] equals "www111.abc.com" } { switch -glob [HTTP::path] { "/secure_one/*" - "/ask_wrap/*" - "/seek_pond/*" { HTTP::redirect "http://www245.abc.com[string map {/secure_one/ /wrap1/ /ask_wrap/ /wrap1/ /seek_pond/ /wrap1/} [HTTP::uri]]" } } } } } [root@ve10:Active] config curl -I http://www111.abc.com/secure_one/anythinghere/image.gif HTTP/1.0 302 Found Location: http://www245.abc.com/wrap1/anythinghere/image.gif Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve10:Active] config curl -I http://www111.abc.com/ask_wrap/anythinghere/anythinghere/image.gif HTTP/1.0 302 Found Location: http://www245.abc.com/wrap1/anythinghere/anythinghere/image.gif Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve10:Active] config curl -I http://www111.abc.com/seek_pond/anythinghere/anythinghere/image.gif HTTP/1.0 302 Found Location: http://www245.abc.com/wrap1/anythinghere/anythinghere/image.gif Server: BigIP Connection: Keep-Alive Content-Length: 0 - vidya_126776
Nimbostratus
Hi Pal (What Lies Beneath) , it was not redirecting. when i tried it popped some error also. tried to fix it.
nitass , thanks for the reply and it worked as expected. - What_Lies_Bene1
Cirrostratus
Thanks for the feedback. Here's a corrected version of my rule above just for reference (which was missing quite a few braces);when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/wrap*" - "/seek*" - "/one*" { HTTP::redirect "http://www111.abc.com[HTTP::uri]" } "/secure_one*" { set replaceURI [string map [list /secure_one /wrap1] [HTTP::uri]] HTTP::redirect "$replaceURI" } "/seek_pond*" { set replaceURI [string map [list /seek_pond /wrap1] [HTTP::uri]] HTTP::redirect "$replaceURI" } "/ask_wrap*" { set replaceURI [string map [list /ask_wrap /wrap1] [HTTP::uri]] HTTP::redirect "$replaceURI" } } }
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