Forum Discussion
Redirect HTTP::uri doesn't work properly.
Hi,
I have some issues with redirecting.
I have the following rules set up :
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/test" } { HTTP::redirect https://usa.acme.com/something } if { [HTTP::uri] starts_with "/mail" } { HTTP::redirect https://usa.acme/webmail_exchange } if { ([HTTP::host] equals "acme.com") } { HTTP::redirect https://usa.acme.com } if { ([HTTP::host] equals "mail.acme.com") } { HTTP::redirect https://mail.acme.com/webmail_zimbra } }
My issue is with :
} if { [HTTP::uri] starts_with "/mail" } { HTTP::redirect https://usa.acme/webmail_exchange }
I don't know for what reason, the redirection doesn't work properly.
I think the issue might be with the fact that the full URL is the one from URL mail.acme.com.
The user needs to type http://mail.acme.com/mail in order to get to https://usa.acme/webmail_exchange, this one doesn't work, while all other rules work as intended.
Any help will be appreciated.
Thanks, Diez
1 Reply
Hi Diez,
actually you've already answered your question yourself... 🙂
if a request for
is received and the ruleset contains those twohttp(s)://mail.acme.com/mail
conditions...[if]if { [HTTP::uri] starts_with "/mail" } then { HTTP::redirect https://usa.acme/webmail_exchange } if { [HTTP::host] equals "mail.acme.com" } then { HTTP::redirect https://mail.acme.com/webmail_zimbra }... then you would send two redirects for the very same request. This will result in an iRule exception (keep an eeye on your LTM logfile) and terminate the TCP connection before the redirect is send.
To solve your problem you could either issue a
command after each singlereturn
/HTTP::redirect
command to stop the processing of the current iRule...HTTP::respondwhen HTTP_REQUEST { if { [HTTP::uri] starts_with "/test" } then { HTTP::redirect "https://usa.acme.com/something" return } if { [HTTP::uri] starts_with "/mail" } then { HTTP::redirect "https://usa.acme/webmail_exchange" return } if { [HTTP::host] equals "acme.com" } then { HTTP::redirect "https://usa.acme.com" return } if { [HTTP::host] equals "mail.acme.com" } then { HTTP::redirect "https://mail.acme.com/webmail_zimbra" return } }... or by creating an collision free rule set...
when HTTP_REQUEST { if { [HTTP::host] equals "acme.com" } then { if { [HTTP::uri] starts_with "/test" } then { HTTP::redirect "https://usa.acme.com/something" } elseif { [HTTP::uri] starts_with "/mail" } then { HTTP::redirect "https://usa.acme/webmail_exchange" } else { HTTP::redirect "https://usa.acme.com" } } elseif { [HTTP::host] equals "mail.acme.com" } then { if { [HTTP::uri] starts_with "/test" } then { HTTP::redirect "https://usa.acme.com/something" } elseif { [HTTP::uri] starts_with "/mail" } then { HTTP::redirect "https://usa.acme/webmail_exchange" } else { HTTP::redirect "https://mail.acme.com/webmail_zimbra" } } }Cheers, Kai
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