Forum Discussion
charlestips_149
Nimbostratus
Jun 30, 2010http to https redirect except for specific URL
We currently have a wildcard cert and virtual server setup so that anyone trying to go to http://www.domain.com/directory gets redirected to https://www.domain.com/directory simple enough
what we would like to do is not redirect for a specific directory.
So redirect for all parts of www.domain.com unless a user goes to http://www.domain.com/specialdirectory
How can I modify the standard http to https irule for that, or should there be a specific irule added for just this.
11 Replies
- hoolio
Cirrostratus
Hi Craig,when HTTP_REQUEST { Check if domain is "www.domain.com" if {[string tolower [HTTP::host]] eq "www.domain.com"}{ Check if URI isn't /specialdirectory switch [HTTP::uri] { "/specialdirectory" { Exit this event from this iRule return } default { Redirect everything else for www.domain.com to HTTPS HTTP::redirect "https://[HTTP::host][HTTP::uri] } } } No other action is taken for hosts which aren't www.domain.com }
when HTTP_REQUEST { Check if domain is "www.domain.com" if {[string tolower [HTTP::host]] eq "www.domain.com"}{ Check if URI isn't /specialdirectory switch [HTTP::uri] { "/specialdirectory" { Exit this event from this iRule return } } } Redirect everything else to HTTPS HTTP::redirect "https://[HTTP::host][HTTP::uri] }
- charlestips_149
Nimbostratus
Thanks guys! I am going to test these out today. Look like perfect options! - charlestips_149
Nimbostratus
Here is what I ended up putting in, which half works. - Chris_Miller
Altostratus
when HTTP_REQUEST { Check if domain is "www.domain.com" if {[string tolower [HTTP::host]] eq "ww2.domain.com"}{ Check if URI isn't /directory if {[HTTP::uri] contains "/directory"} { return } } Redirect everything else to HTTPS HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] }
- charlestips_149
Nimbostratus
I tried "/directory/*" but it didn't work, I tried without the close quote like you have but I get a parse error that way. - Chris_Miller
Altostratus
Posted By charlestips on 07/06/2010 01:29 PM - Michael_Yates
Nimbostratus
There is no need to do a string tolower on the [HTTP::host] values. - charlestips_149
Nimbostratus
If I use your latest Chris the page returns - hoolio
Cirrostratus
In theory, the Host header could be set by the client in upper, lower or mixed case and the server must interpret it with out case sensitivity. So to follow RFC2616, you should actually set the Host header value to lower case before checking it. In practice, all major browsers set the Host header value to lower case. I think most applications would be case sensitive for the query string. For IIS, the path isn't case sensitive.when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]" Check if domain is "www.domain.com" if {[string tolower [HTTP::host]] eq "ww2.domain.com"}{ Check if URI doesn't start with /directory if {[string tolower [HTTP::path]] starts_with "/directory"} { log local0. "[IP::client_addr]:[TCP::client_port]: Allowing request through" Exit this event from this iRule return } } Redirect everything else to HTTPS HTTP::redirect "https://[getfield [HTTP::host] ":" 1][HTTP::uri]" log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting request" }
- charlestips_149
Nimbostratus
I am sorry, the coder was messing with his script at the same time. This works perfectly. Thanks everyone, for your contributions!
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