Forum Discussion
adamo_1516
Nimbostratus
Aug 14, 2007exception logic for selective https redirect
yes, i'm losing my mind.
i've got a rule we put in place to take specific subdomains and statically redirect the URL's to https. it works great, but we're now seeing we need to add exception logic for a specific URI beforehand, and i've been unable to figure it out.
our existing rule looks like this:
when HTTP_REQUEST {
if { ([HTTP::host] starts_with "subdomain1." ) or ([HTTP::host] starts_with "subdomain2.") } {
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
}
we need to add logic for this:
if { ([HTTP::uri] contains "SpecialUrl") } {
then it needs to allow HTTP, and *NOT* redirect to HTTPS. i'm thinking an 'else' would do it, but i'm not so sure what to do for the statement for the action.. would an HTTP redirect to the same exact URL work (simiular to this):
HTTP::redirect http://[HTTP::host][HTTP::uri]
i just can't get any of this to tie together, and really need to get this working since our prod environment now has an issue. any help appreciated!!
-adam
- hoolio
Cirrostratus
If you want to redirect if the host starts with sub1 or sub2, but not if the URI contains the special string, you can use 'not':when HTTP_REQUEST { if { ([HTTP::host] starts_with "subdomain1." or [HTTP::host] starts_with "subdomain2.") and (not ([HTTP::uri] contains "SpecialUrl"))} { HTTP::redirect https://[HTTP::host][HTTP::uri] } }
- adamo_1516
Nimbostratus
awesome! i'm going to give this a try tonight. - Craig_Holland_2
Nimbostratus
How about: - hoolio
Cirrostratus
First, I saw a more eloquent way to parse the subdomain from the getfield wiki page (Click here)"class redirect_hosts { subdomain1. subdomain2. subdomain3. }
when HTTP_REQUEST { if {([matchclass [getfield [string tolower [HTTP::host]] "example.com" 1]] equals $::redirect_hosts) and (not ([HTTP::uri] contains "SpecialUrl"))} { HTTP::redirect https://[HTTP::host][HTTP::uri] } }
if {not ([HTTP::path] contains "SpecialUrl")}{ use getfield to split the host header value and grab anything that comes before "example.com" set that remaining string to lower case switch [getfield [string tolower [HTTP::host]] "example.com" 1] { subdomain1. - subdomain2. - subdomain3. { redirect matching requests to https HTTP::redirect https://[HTTP::host][HTTP::uri] } default { do nothing; let request be sent to pool per VIP configuration } } }
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