Forum Discussion

HELITG_35878's avatar
HELITG_35878
Icon for Nimbostratus rankNimbostratus
Aug 08, 2006

iRule for HTTP to HTTPS using a specific pool for a specific virtual directory

Hi everyone,

 

 

I'm new to writing irules and I need some guidance on this one.

 

 

For a specific virtual directory I want to ensure all visitors use ssl

 

 

i.e

 

for requests to anything beginning http://www.site.com/secure1

 

I want the uri to be re-written as

 

https://www.site.com/secure1

 

and be directed to use a specific pool, say pool1

 

 

I was thinking on the lines of

 

 

when HTTP::REQUEST {

 

if ((http_host matches_regex "www.site.com") and (http_uri starts_with "/secure1"))

 

{

 

HTTP::redirect https://[HTTP::Host][HTTP::uri]

 

}

 

 

Any help would be appreciated.

 

Thanks in advance.

2 Replies

  • That looks like a good start as far as logic goes. I would suggest using contains, starts_with or equals instead of matches_regex, unless you really need to use a regular expression to match the hostname as matches_regex is more resource intensive that the string comparisons.

    The redirect syntax you are using is from 9.x though, not 4.x. To redirect a request in 4.x, try this format:

    
    if ((http_host equals "www.site.com") and (http_uri starts_with "/secure1")) {
       redirect to "https://www.site.com" + http_uri
    }

    If you want to specify the pool when the client is redirected to HTTPS, you would want to create another rule on the loopback VIP the SSL proxy points to that sets a pool based on the URI. Here is an example for that rule:

    
    if (http_uri starts_with "/secure1") {
       use pool pool1
    } 
    else {
       use pool default_pool
    }

    Aaron