Forum Discussion
Partial Redirect based on URI
First thing, a URI will always exist. If the client enters nothing in the browser, then the URI will simply be "/".
Second thing, your iRule can be super simplified with a data group, which not only makes the iRule shorter, but makes the list of redirected URIs easier to manage. Example:
A string-based data group (ex. my_redirect_class)
"/default.asp" := ""
"/cash-cards-and-lending/cards/" := ""
"/cash-cards-and-lending/cards/default.asp" := ""
"/default-client.asp" := ""
"/cash-cards-and-lending/cards/american-express-gold-card.asp" := ""
"/cash-cards-and-lending/cards/american-mastercard.asp" := ""
"/cash-cards-and-lending/cards/american-world-elite-mastercard.asp" := ""
"/cash-cards-and-lending/cards/american-world-mastercard.asp" := ""
"/cash-cards-and-lending/cards/platinum-card-from-american-express.asp" := ""
"/client-login/default.asp" := ""
"/client-login" := ""
"/client-login/esignature.asp" := ""
"/client-login/logout.asp" := ""
"/client-login/message-center/retrieve.asp" := ""
"/Quicken" := ""
"/Quicken/default.asp" := ""
And then the iRule:
when HTTP_REQUEST {
if { [HTTP::uri] equals "/" } {
HTTP::redirect "https://[HTTP::host]/"
} elseif { [class match [string tolower [HTTP::uri]] contains my_redirect_class] } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
}
So if the URI equals "/" (nothing), redirect to the same host on HTTPS. If the URI contains any of the values in the data group, redirect to that URL on HTTPS. Otherwise do nothing.
You could probably further simplify the data group by taking out some overriding values and use a "starts_with" condition in the iRule.
"/default.asp" := ""
"/cash-cards-and-lending/cards" := ""
"/default-client.asp" := ""
"/client-login" := ""
"/Quicken" := ""
when HTTP_REQUEST {
if { [HTTP::uri] equals "/" } {
HTTP::redirect "https://[HTTP::host]/"
} elseif { [class match [string tolower [HTTP::uri]] starts_with my_redirect_class] } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]"
}
}
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