Forum Discussion
Redirect from WWW iRule
Hello all !
How can I redirect traffic from "www.example.com" to "https://example.com", I don't care if it's an iRule or policy.
I tried iRules, policies, and nothing worked, all other redirects I created work fine.
Thanks, Yan
Hi Yan,
1. string map
when HTTP_REQUEST { if { [HTTP::host] starts_with "www." } { HTTP::redirect https://[string map {www. ""} [HTTP::host]][HTTP::uri] } }
2. string range
when HTTP_REQUEST { if { [HTTP::host] starts_with "www." } { HTTP::redirect https://[string range [HTTP::host] 4 end][HTTP::uri] } }
3. getfield
when HTTP_REQUEST { if { [HTTP::host] starts_with "www." } { HTTP::redirect https://[getfield [HTTP::host] "www." 2][HTTP::uri] } }
4. substr
when HTTP_REQUEST { if { [HTTP::host] starts_with "www." } { HTTP::redirect https://[substr [HTTP::host] 4][HTTP::uri] } }
- YanikAltocumulus
Thanks for the answer, but no one of the iRules doesn't work.
When I log the iRule I see "SSL Handshake failed for TCP", so may be I have some other issue and not iRule, so I will investigate it.
- AlexBCTCumulonimbus
Hi Yanik,
That sounds like a different issue indeed. You may want to confirm that you have the iRule attached to the port 80 virtual server, rather than the 443 virtual server. Also, check that the port 80 virtual server doesn't have any SSL profiles on it.
Or if it is supposed to be redirected from https://www.example.com to https://example.com, then you DO need an SSL profile on the virtual server, so that the iRule can read the unencrypted request.
Hope this helps.
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