Forum Discussion
I want to Redirect multiple Sites in a single Irule. please help me with the irule command.
I have mulitple sites where i want my LAN users should not to redirected to https when they use url with http. but when any internet users use http://abc.com than it should redirect to https://abc.com
Can i use the below irule for this.
when HTTP_REQUEST { if {[HTTP::host] equals "abc.com"} { HTTP::redirect "https://abc.com[HTTP::uri]" } }
Now i want to do for multiple sites in same irule can i use another if statement?
49 Replies
This irule will work. You may change it to fit for your need of multiple sites :
when HTTP_REQUEST { switch -glob [HTTP::host] { "hostname1" { HTTP::redirect "https://hostname1[HTTP::uri] } "hostname1" { HTTP::redirect "https://hostname1[HTTP::uri] } "hostname2" { HTTP::redirect "https://hostname2[HTTP::uri] } default { } } }If this is just for redirecting http to https, you can just use this irule :
when HTTP_REQUEST { HTTP::redirect "https://[HTTP::host][HTTP::uri]" }- nitass
Employee
I have mulitple sites where i want my LAN users should not to redirected to https when they use url with http. but when any internet users use http://abc.com than it should redirect to https://abc.com
you may use IP::addr to check whether it is lan user traffic and then redirect if not.
e.g.
config [root@ve11a:Standby:In Sync] config tmsh list ltm virtual bar ltm virtual bar { destination 172.28.24.10:80 ip-protocol tcp mask 255.255.255.255 pool foo profiles { http { } tcp { } } rules { qux } source 0.0.0.0/0 source-address-translation { type automap } vs-index 65 } [root@ve11a:Standby:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { if { !([IP::addr [IP::client_addr] equals 172.28.24.0/24]) } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } } } test1 (client ip is 172.28.24.11) [root@ve11a:Standby:In Sync] config curl -I http://172.28.24.10/ HTTP/1.1 200 OK Date: Wed, 20 Aug 2014 07:08:10 GMT Server: Apache/2.2.3 (CentOS) Last-Modified: Sun, 09 Feb 2014 08:39:51 GMT ETag: "41879c-59-2a9c23c0" Accept-Ranges: bytes Content-Length: 89 Content-Type: text/html; charset=UTF-8 test2 (client ip is 172.28.77.29) curl -I http://172.28.24.10/ HTTP/1.0 302 Found Location: https://172.28.24.10/ Server: BigIP Connection: Keep-Alive Content-Length: 0
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