Forum Discussion

Shlairshe_84486's avatar
Shlairshe_84486
Icon for Nimbostratus rankNimbostratus
Mar 20, 2015

Assistance with multiple instance i-Rule using multiple http to https redirect

I am in what is referred to as HOT waters. I really need a solution to this issue by 11pm tonight.

 

Below is the irule I have working (v 11.4)

 

when HTTP_REQUEST { set req [string tolower [HTTP::uri]] if { $req starts_with "/artic"

 

} {HTTP::redirect "https://[HTTP::host][HTTP::uri]"} use pool toplevel1 if { $req starts_with "/ports"} { HTTP::redirect "" } }

 

The above i-Rule works fine,

 

--- > when I access the url http://darten.seng.tts.com/artic I reach the desired site and the http to https redirect works.

 

--- > The same applies to when I access the url http://darten.seng.tts.com/ports, I get redirect to the server1:8080/TOE/BOC url.

 

My problem is. I am adding two more URI'S and i need to have each URI reachable via https from http.

 

THIS IS WHAT I HAVE PREPARED :

 

when HTTP_REQUEST { set req [string tolower [HTTP::uri]] if { $req starts_with "/artic" } HTTP::redirect "https://[HTTP::host][HTTP::uri]" use pool toplevel1 if { $req starts_with "/extartic1" } HTTP::redirect "https://[HTTP::host][HTTP::uri]" use pool retop if { $req starts_with "/ports" } HTTP::redirect "" use pool Porting_Pool }

 

In effect, for eact /uri --> /artic, /extartic1 and /ports, I want to be able to be redirected from http to https. To clearly explain

 

--- > When a user accesses http://darten.seng.tts.com/artic --- > I want to be able to get to this site/uri ending in https://darten.seng.tts.com/artic (going from http to https)

 

--- > Whe a user accesses http://darten.seng.tts.com/extartic1 --- > I want to be able to get to the site/uri executing to https://darten.seng.tts.com/extartic1 (going from http to https)

 

--- > when a user enters http://darten.seng.tts.com/port --- > I want to be able to get to the site/uri executing to https://darten.seng.tts.com/ports (going from http to https)

 

Really need some help as soon as possible.

 

4 Replies

  • he_qiang_137361's avatar
    he_qiang_137361
    Historic F5 Account

    Here is the iRule,

     

    when HTTP_REQUEST {
    
        switch -glob [string tolower [HTTP::uri]] {
            "/artic*" {
                HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
            }
    
            "/extartic1*" {
                HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
            }
    
            "/port*" {
                HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
            }
        }
    
    }
    

     

    Hope it helps, :).

  • Hi Shlairshe,

    if I got it right, you want to redirect to https only for exact match and in case of path starting with a specific pattern a specific pool should be selected.

    The following one should meet your requirements after adjusting the path and pool specification:

     

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::path]] {
            "/path1" { HTTP::redirect https://[getfield [HTTP::host ] ":" 1][HTTP::uri]
            "/path1/*" { pool  }
            "/path2" { HTTP::redirect https://[getfield [HTTP::host ] ":" 1][HTTP::uri]
            "/path2/*" { pool  }
            "/path3" { HTTP::redirect https://[getfield [HTTP::host ] ":" 1][HTTP::uri]
            "/path3/*" { pool  }
        }
    }
    

     

    The "-glob" allows using wildcards and exact match versus the requested path. Exact matches will be redirected to https. Matches equivalent to "starts_with" ("/path/*") will simply forward to the resource pool. Please notice also the difference between path and uri (containing the path and the query of the requested url. Perhaps you want to change the "switch" command to "switch -glob [string tolower [HTTP::uri]]" in case there is a query following the path. But in this case we would probably need to modify the whole iRule.

    It will probably be required to use a OneConnect profile on your virtual server. The syntax "use pool " is deprecated. Please code "pool ".

    Thanks, Stephan

  • Thanks very much Stephan,

     

    It work so far, just have to include some new additions but I get the picture. I was a bit off in the way my code was written.

     

    Thanks very much for your input.

     

    The solution per devcentral requirements "WORKED"

     

    Steven.