Forum Discussion
3 part redirect irule query. non www to www to https
Hello All
We recently moved over to F5's from another load balancer product and have been gradually moving our staging and live services over after testing has been completed. However one issue has come up. On our previous load balancer there was a http redirect in place so that when users tried to access our SharePoint site without the www. prefix it would redirect them to a specific url e.g. https://www.sharepointsite.com/sites/homepage.aspx
We have it set in the SharePoint 2013 iApp to redirect http traffic to https but my understanding is to do non www to www. we need a iRule. Is that correct? I realise this may sound a fairly trivial issue but all will become clear shortly.
The reason why this isn't trivial is because I won't be able to test this on our staging area, I can only apply it on live, so I have to ensure I get it right. The reason for this is our staging area is https://staging.sharepointsite.com so the iRule wont be the same as if I was redirecting non www to www.
I've spent some time searching on here and haven't found anyone else in exactly the same situation but did find a rule that I think will work. Please can you advise if what I've written below will work if I introduce it into a SharePoint 2013 iApp's config as a iRule. Or if not can you offer advice on what will work please.
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] ends_with "sharepointsite.com" } {
HTTP::redirect "https://www.sharepointsite.com[HTTP::uri]"
}
}
That to me looks like it should work but I wondered if that maybe wouldn't be the case when introduced to a iApp. Or if it may take issue with the face theres no dot/fullstop/period before the initial sharepointsite.com
Thanks in advance
Rhys.
- Rhys_Davis_2151NimbostratusOK been some slight developments from the original request and after some reading around...... now have it setup as follows when HTTP_REQUEST { if { [string tolower [HTTP::host]] starts_with "http://sharepointsite.com" } { HTTP::redirect "https://www.sharepointsite.com[HTTP::uri]" } } which should take all the url and redirect it to https and then include all the bits after .com/ I also need to do the same for https so I'm guessing I want when HTTPS_REQUEST { if { [string tolower [HTTP::host]] starts_with "https://sharepointsite.com" } { HTTP::redirect "https://www.sharepointsite.com[HTTP::uri]" } } Does that look right to you all? also will these need to be separate irules or can they be lumped into one?
- Stanislas_Piro2Cumulonimbus
Hi,
Host header does not include scheme... remove https in your if statement.
for both HTTP and HTTPS, the event is the same (HTTP_REQUEST) : HTTPS is HTTP over SSL
the irule must be:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "sharepointsite.com" } { HTTP::redirect "https://www.sharepointsite.com[HTTP::uri]" } }
- ArieAltostratus
If you always want to redirect from HTTP to HTTPS I would recommend using a 301 (permanent redirect) as opposed to the 302 (temporary redirect) that is generated by
. A permanent redirect is cached by clients so it saves on HTTP-requests.HTTP::redirect
You accomplish this by replacing
withHTTP::redirect "https://www.sharepointsite.com[HTTP::uri]"
.HTTP::respond 301 Location "https://www.sharepointsite.com[HTTP::uri]"
You can further optimize by using HSTS, which instructs clients to use HTTPS for subsequent requests even if the link specifies HTTP.
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