cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Redirect from WWW iRule

Yanik
Altostratus
Altostratus

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

3 REPLIES 3

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] } }

 

Yanik
Altostratus
Altostratus

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.

 

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.