Forum Discussion
Redirect on HTTP::host does not work
Here is the configuration. 2 virtuals, same IP address, port 80 is using built in _sys_https_redirect iRule; Port 443 uses the below iRule and an additional that triggers on responses only. They are ordered to with this iRule first, and the response iRule second. I inherited this configuration and am trying to correct a deficiency with as little change as possible (mgmt. reasons for that). My issue is the first "if" in this iRule doesn't seem to trigger. If I enter "http://ourdomain.com" or "https://ourdomain.com" I do not get redirected to the www.ourdomain.com page; although if I enter "http://ourdomain.com" I do get redirected to "https://ourdomain.com". The 2nd and 3rd conditions in this iRule work flawlessly. I'm hoping this is just something where someone points out something simple and stupid I should have caught...
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] starts_with "ourdomain.com" } {
HTTP::redirect https://www.ourdomain.com[HTTP::uri]
}
if { ([HTTP::uri] eq "/") or ([HTTP::uri] eq "") } {
HTTP::redirect https://www.ourdomain.com/abc/portal/place
}
elseif { ( [HTTP::uri] contains "/mydomainLandingPage" ) } {
HTTP::redirect "https://www.ourdomain.com/abc/portal/place/PageNotFound/"
}
}
1 Reply
- Kevin_Stewart
Employee
I believe the issue is that you're not terminating evaluation after the first condition. You may be matching on the first condition, but the iRule is going to continue parsing the iRule. Try moving everything into a single if/elseif structure:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] starts_with "ourdomain.com" } { HTTP::redirect https://www.ourdomain.com[HTTP::uri] } elseif { [HTTP::uri] eq "/" } { HTTP::redirect https://www.ourdomain.com/abc/portal/place } elseif { ( [HTTP::uri] contains "/mydomainLandingPage" ) } { HTTP::redirect "https://www.ourdomain.com/abc/portal/place/PageNotFound/" } }Also, you don't need the or ([HTTP::uri] eq "") section. An empty URI will always, at a minimum, contain a "/" character.
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