Forum Discussion
http to https redirect working but want to add www.
Hi,
This iRule is working to redirect http to https and leaving the hostname intact. Exactly what I want.
when HTTP_REQUEST {
HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}
My problem here is, when customers type in http://abc.com (notice no ) I want it to redirect to https://www.abc.com not just https://abc.com which is giving me a cert error.
How would you write the if/else statement so www. appends to the request?
Thank you in advance.
4 Replies
- Antony2015
Altostratus
Hi Sonny,
Please try with the irule below.
when HTTP_REQUEST { if { [HTTP::host] starts_with "abc.com" } { HTTP::redirect https://www.abc.com[HTTP::uri] } }
Thanks.
Anto
- Sonny_J_Bonds_1
Nimbostratus
Thank you Anto, I will give this a try today and report back with my results.
- Sonny_J_Bonds_1
Nimbostratus
Anto, thanks for your help to get things started for me. That partially worked but it didn't redirect http://www.abc.com to only http://abc.com redirected to https://www.abc.com. Needed both incoming request as http (www. and no www) to be redirected to https://www.abc.com.
For my situation, I got it to work with this:
when HTTP_REQUEST { if { [HTTP::host] contains "abc"} { HTTP::redirect https://www.abc.com[HTTP::uri] } } - Stanislas_Piro2
Cumulonimbus
Your irule does not include uppercase URLs:
the following irule will allow you to redirect needed hosts:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "abc.com" - "www.abc.com" - "*.abc.com" { HTTP::redirect https://www.abc.com[HTTP::uri] } } }I added www.abc.com and *.abc.com to show different ways with switch command.
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