Forum Discussion
*Redirect http to https and remove www from URL*
Following iRule, removes www from URL. But, can we also redirect http to https at same time with same iRule?
if {[string tolower [HTTP::host]] starts_with "www."} {
HTTP::redirect "http://[string range [HTTP::host] 4 end][HTTP::uri]"
}
}
6 Replies
- El-Guapo_29797
Nimbostratus
Also, adding to this, can same iRule be used to modify any http site (not specific) such as http://xyz.com to https://xyz.com. I am trying to do two things in same iRule. - Kevin_Stewart
Employee
Just use "https://" in your redirect.
HTTP::redirect "https://..." - nitass
Employee
can same iRule be used to modify any http site (not specific) such as http://xyz.com to https://xyz.com.
e.g.
[root@ve11a:Active:Changes Pending] config tmsh list ltm virtual bar ltm virtual bar { destination 172.28.20.111:80 ip-protocol tcp mask 255.255.255.255 profiles { http { } tcp { } } rules { myrule } source 0.0.0.0/0 source-address-translation { type automap } vs-index 28 } [root@ve11a:Active:Changes Pending] config tmsh list ltm rule myrule ltm rule myrule { when HTTP_REQUEST { HTTP::redirect "https://[string map {"www." ""} [HTTP::host]][HTTP::uri]" } } [root@ve11a:Active:Changes Pending] config curl -I http://172.28.20.111/something -H "Host: www.xyz.com" HTTP/1.0 302 Found Location: https://xyz.com/something Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve11a:Active:Changes Pending] config curl -I http://172.28.20.111/something -H "Host: xyz.com" HTTP/1.0 302 Found Location: https://xyz.com/something Server: BigIP Connection: Keep-Alive Content-Length: 0 - El-Guapo_29797
Nimbostratus
thanks so much for the answers.. i will try both.
- Kevin_Stewart
Employee
That's one way to do it. You can also use Nitass' [string map ] recommendation, or even some [findstr ] syntax:
when HTTP_REQUEST { if { [string tolower [HTTP::host]] starts_with "www." } { HTTP::redirect "https://[findstr [string tolower [HTTP::host]] "www." 4][HTTP::uri]" } } - El-Guapo_29797
Nimbostratus
Kevin: Thank you so much.. This worked great. when HTTP_REQUEST { if { [string tolower [HTTP::host]] starts_with "www." } { HTTP::redirect "https://[findstr [string tolower [HTTP::host]] "www." 4][HTTP::uri]" } }
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