Forum Discussion
iRule Redirect loop
Hi
I am trying to achieve a simple URL redirect but I keep getting a redirect loop or nothing at all. I get an error of "too many redirects"
Condition 1
All requests to "; must be redirected to https://test.tst.train123.com/trace123 only
But any other traffic eg. "; must continue to the default pool
My problem is when I use the the irule below I get a redirect loop
when HTTP_REQUEST { if { [HTTP::host] equals "test.tst.train123.com" } { HTTP::redirect "https://test.tst.train123.com/Trace123 [HTTP::uri]" } }
When I try this it doesnt seem to work either. I know I am missing something
when HTTP_REQUEST { if { [HTTP::uri] equals "test.tst.train123.com"} { HTTP::redirect "/Trace123" } elseif { [HTTP::uri] equals "; } { pool pool_trace123 } }
- Stanislas_Piro2
Cumulonimbus
Hi,
if the virtual server only provides service for host test.tst.train123.com, use following code :
when HTTP_REQUEST { if {[HTTP::path] equals "/" } { HTTP::redirect "/Trace123" } }
else you must filter on the host header
when HTTP_REQUEST { if { [HTTP::host] equals "test.tst.train123.com" && [HTTP::path] equals "/" } { HTTP::redirect "/Trace123" } }
if not required by hostname change or protocol change (http to https redirect), please use "relative URL absolute path" URI in redirect (without protocol and host, but full path)
- JG
Cumulonimbus
Not totally sure of your requirement, but I will still a venture a reply, if only serving as a pointer:
when HTTP_REQUEST { if { [HTTP::host] equals "test.tst.train123.com" } { switch -exact [string tolower [HTTP::path]] { "/" { HTTP::redirect "https://test.tst.train123.com/Trace123" } default { pool pool_trace123 } } } }
An LTM policy would actually be a better option, and its building process would guide you through it in a more transparent way and therefore be helpful to you.
[Edited]
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