Forum Discussion
Bertolazzi_7869
Nimbostratus
Apr 18, 2012HTTP Redirect: Hint or an example?
7 Replies
- nitass
Employee
do you want redirection or rewriting?
Redirect vs. Rewrite
http://cheeso.members.winisp.net/iirf20Help/html/2e820208-c2eb-4d6d-a134-c63f7d41244f.htm
this is an example of redirection.[root@ve1023:Active] config b virtual bar list virtual bar { snat automap pool server destination 172.28.19.79:8080 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { if { [HTTP::uri] equals "/ABC" } { HTTP::redirect "http://[HTTP::host]/DEF" } } } [root@ve1023:Active] config curl -I http://www.mydomain.com:8080/ABC HTTP/1.0 302 Found Location: http://www.mydomain.com:8080/DEF Server: BigIP Connection: Keep-Alive Content-Length: 0 - Michael_Yates
Nimbostratus
Hi Bertolazzi,
Try this:when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/abc" } { HTTP::redirect [string map {"abc" "def"} [HTTP::uri]] } }
This iRule some assume that you just want to replace the sub-directory "abc" with "def" and keep the rest of the HTTP::uri.
If you are needing something else just let us know.
Hope this helps. - Bertolazzi_7869
Nimbostratus
Nitass and Michael, tks for your reply!
I will test now and post the results. - Bertolazzi_7869
Nimbostratus
Hi,
The redirection works fine with Nitass code!
Please, tell me if this configuration is correct:
http://www.mydomain.com:8080/ABC redirects to http://www.mydomain.com:8080/DEF and points to the pool pool_def
http://www.mydomain.com:8080/HIJ redirects to http://www.mydomain.com:8080/KLM and points to the pool pool_klmwhen HTTP_REQUEST {
if { [HTTP::uri] equals "/abc" } {
HTTP::redirect "http://[HTTP::host]/def"{
"/abc*" {pool pool_def}}}
if { [HTTP::uri] equals "/hij" } {
HTTP::redirect "http://[HTTP::host]/klm"{
"/hij*" {pool pool_klm}}
}
}
tks. - Bertolazzi_7869
Nimbostratus
Hi,
I searched here in the forum and found a thread on redirection to pool, so I created two iRules.
1º - iRule - pool redirection
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/abc*" {pool pool_def}
"/hij*" {pool pool_klm}
}
}
2º iRule - http redirection
when HTTP_REQUEST {
if { [HTTP::uri] equals "/abc" } {
HTTP::redirect "http://[HTTP::host]/def/"
}
if { [HTTP::uri] equals "/hij" } {
HTTP::redirect "http://[HTTP::host]/klm/"
}
}
I was successful in the tests that I performed, but i don't know if this way is the best.
I will continue performing the tests and keep everyone updated.
Tks. - nitass
Employee
i think Michael's irule is more general. by the way, you may combine two irules together.
e.g.[root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { switch [HTTP::uri] { "/ABC" { HTTP::redirect "http://[HTTP::host]/DEF" } "/HIJ" { HTTP::redirect "htt://[HTTP::host]/KLM" } "/DEF" { pool pool_def } "/KLM" { pool pool_klm } } } } - Bertolazzi_7869
Nimbostratus
Nitass
I tested with your iRule and worked.
Tks.
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