Forum Discussion
Juan_María_Rodr
Nimbostratus
Mar 02, 2006redirect and loop, please help
Hello.
Could anyone tell me why this iRule ends in a loop?
when HTTP_REQUEST {
if { [HTTP::host] equals "www.pepito.com"} {
HTTP::redirect "http://www.pepito.com/maintenance/index.html"
}
}
Thank you.
6 Replies
- JRahm
Admin
The redirect is using the same host that the if condition is looking for. Are you trying to match for an empty URI? If so, try something like this:when HTTP_REQUEST { if { ([ string length [HTTP::uri] ] <= 1) } { if { [HTTP::host] equals "www.pepito.com"} { HTTP::redirect "http://www.pepito.com/maintenance/index.html" } } }
NOTE: Not Tested! - Juan_María_Rodr
Nimbostratus
Thank citizen, but I'd like that when I access to www.pepito.com, it is redirected to www.pepito.com/maintenance/index.html. I don`t know how to do that. For example, I tried these:
when HTTP_REQUEST {
if { [HTTP::path] equals "www.pepito.com"} {
set [HTTP::uri] "/maintenance/index.html"
HTTP::redirect "http://[HTTP::host][HTTP::uri]"
}
}
when HTTP_REQUEST {
if { [HTTP::host] equals "www.pepito.com" and [HTTP::uri] equals ""} {
set [HTTP::uri] "/maintenance/index.html"
HTTP::redirect "http://[HTTP::host][HTTP::uri]"
}
}
when HTTP_REQUEST {
if { [HTTP::host] equals "www.pepito.com" and [HTTP::uri] equals ""} {
HTTP::redirect "http://[HTTP::host]/maintenance/index.html"
}
}
In these cases, I stayed in www.pepito.com and I wasn´t redirected to www.pepito.com/maintenance/index.html.
Help SOS
Thanks - JRahm
Admin
My previous post should function the same as your 2 attempt. - The value of HTTP::uri will never by empty. It will at least always contain the beginning "/" character. So your conditions of the URI equalling "" will never pass.
Another option would be the following (if you want all requests to go the maintenance page).when HTTP_REQUEST { if { ([string tolower [HTTP::host]] equals "www.pepito.com") and ([string tolower [HTTP::uri]] ne "/maintenance/index.html") } { HTTP::redirect "http://www.pepito.com/maintenance/index.html" } }
This will redirect all requests to the www.pepito.com domain to the maintenance page except for ones already going to the maintenance page (thus avoiding the infinite loop).
I threw in some "string tolowers" so that it would match mixed case requests as well.
Citizens example will redirect either "http://www.pepito.com" or "http://www.pepito.com/" while mine will redirect all requests. Pick your choice...
-Joe
} - Juan_María_Rodr
Nimbostratus
Thank you very much. It works.
But, could you tell me why this one doesn't work?:
when HTTP_REQUEST {
if { [HTTP::path] equals "www.pepito.com"} {
set [HTTP::uri] "/maintenance/index.html"
HTTP::redirect "http://[HTTP::host][HTTP::uri]"
}
}
Thanks a lot. - JRahm
Admin
By including the brackets on the HTTP::uri, you are setting a variable name to the value of HTTP::uri. For example, if your URI is only "/", then the equivalent would be
set / "/maintenance/index.html"
Which may not throw an error when updated but probably will error out when evaluated.
It would be better written:
HTTP::uri "/maintenance/index.html"
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
