Forum Discussion
Marker_58065
Dec 15, 2010Nimbostratus
Append domain when needed and redirect to HTTPS
Here is the background - we have a couple of internal F5s with a bunch of applications that we are doing SSL offloading on. When users access these applications they don't have to type the FQDN because of a dns search suffix. So if a user types 'sharepoint' in the browser, it resolves 'sharepoint.ourdomain.net' but the host header only has 'sharepoint' and not the FQDN. We like to use one general rule for redirecting to HTTPS on our virtuals when possible. We use the following rule external:
when HTTP_REQUEST {
HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}
Which works great with a FQDN, but we would like to have something similar that looks to see if the the host request has the FQDN and if not, append it, then redirect to HTTPS. Here is something i have come up with, but I wanted to know if maybe there is a better way.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
*.ourdomain.net {
HTTP::redirect https://[HTTP::host][HTTP::uri]
} default {
HTTP::redirect https://[HTTP::host].ourdomain.net[HTTP::uri]
}
}
}
Today we just build a custom redirect irule per application, but we would like a generic one we can apply across multiple virtuals. Any feedback you would have would be great.
Thanks.
- hooleylistCirrostratusHi Marker,
- Marker_58065NimbostratusThanks for the quick reply. No, we do not access them by IP address, though if I was using that irule I would probably put '10.* -' on the first match string. If someone used an IP I would want it to work, but wouldn't care if they got a cert error. Our company actually uses your 2nd solution today and it works great, I am just trying to see about a more efficient way (I am lazy...I know).
- hooleylistCirrostratusHere's an example of the datagroup mapping:
Datagroup mapping the VS IP to hostname class redirect_vs_to_host_class { { host 1.1.1.1 { "vs1.example.com" } host 1.1.1.2 { "vs2.example.com" } host 1.1.1.3 { "vs3.example.com" } } } iRule which references the above datagroup when HTTP_REQUEST { Look up the VS IP in the IP to hostname datagroup set match [class search -value redirect_vs_to_host_class equals [IP::local_addr]] If a match was found redirect to the hostname from the class if {$match ne ""}{ HTTP::redirect https://$match[HTTP::uri] } else { Take some default action? HTTP::redirect https://[HTTP::host][HTTP::uri]" } }
- hooleylistCirrostratusAnother option would be to name the virtual server with the FQDN that is in DNS and then parse [virtual name] to get the correct hostname. You could avoid manually configuring the IP to hostname mappings with this. A caveat is that you can't rename virtual servers via the GUI. The example below uses the virtual server name up to the first underscore:
virtual www.example.com_http_vs { destination 10.1.0.15:80 ip protocol tcp rules vs_name_to_redirect_rule profiles { http {} tcp {} } }
when HTTP_REQUEST { log local0. "parsed https://[getfield [virtual name] _ 1][HTTP::uri]" HTTP::redirect "https://[getfield [virtual name] _ 1][HTTP::uri]" }
- Marker_58065NimbostratusI like both of your examples. I think I will try and use your second example because we do use FQDN for our virtual server names and it would be simpler to implement. Thanks for your help!
- Marker_58065NimbostratusThanks again..the vs_name script works great. I have another somewhat related question. We have one virtual that is doing redirects so are users can have easier access to sites. Right now, we are using a 'switch -glob' irule to match and I would like to move to datagroups. Here are my questions:
- hooleylistCirrostratusCan you clarify for scenario 1 why you wouldn't redirect all HTTP requests to HTTPS using the statically assigned hostname which matches the cert for the HTTPS virtual server? Or are you referring to something different?
- Marker_58065NimbostratusSorry about the confusion...this one is totally different. Now I am just taking about a standard url redirect, like a user puts in 'site1' and gets sent to 'http://sharepoint.domain.net/somesite/etc/'. I got about 300 of them all on 1 virtual. I have the same problem with not always getting the full domain in the host request. Today I have this:
- hooleylistCirrostratusThanks for clarifying. I like your use of string map to remove the domain before doing the class lookup. If that works, it looks efficient and easy to administer to me.
- Marker_58065NimbostratusSounds good. Thanks again for your help.
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