Forum Discussion

Girish_HS_32793's avatar
Girish_HS_32793
Icon for Nimbostratus rankNimbostratus
Aug 05, 2008

Help: Redirect to https with URI

Hi Team,

 

 

I have a iRule setup for http which checks for URI and assigns the Node & port to be used.

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] equals "mysite.someplace.com"} {

 

if { [HTTP::uri] starts_with "/abc" } {

 

node 10.244.8.34 9001

 

}

 

}

 

}

 

 

Now I need to redirect http://mysite.someplace.com to https://mysite.someplace.com, check for URI and use specific node and port.

 

 

How do I achieve this?

 

 

3 Replies

  • Checking the URI and using a specific IP and port is what the rule you posted does. Can you clarify what you're trying to accomplish?

     

     

    Thanks,

     

    Aaron
  • Hi Aaron, I will try to explain what I need to accomplish.

     

    I have a total of 4 apps registered to 1 Public IP address, All the 4 apps have a specific homepage, out of the 4 apps I have one app which has its specific home page and also running another application which is determined by its URI.

     

    As of now I have setup a iRule which will look for the HOST and redirect it to its specific homepage. All the 4 HOST's have different names.

     

    What I want to accomplish is, (1) I want to redirect all HTTP request for the 4 apps to HTTPS and (2) as said, one of the 4 apps is also using a different application which is determined by the URI, I want to redirect this application also to HTTPS and also this application runs on one of the nodes where as the others are hosted on 2 nodes and loadbalanced.

     

    the present setup is like this:

     

     

    1) http://order.asia.com/homepage_asia

     

    2) http://order.asia.com/xyz

     

    3) http://order.aus.com/homepage_aus

     

    4) http://order.amr.com/homepage_amr

     

    5) http://order1.eur.com/homepage_eur

     

     

    I have setup a iRule to redirect 1,3,4,5 (URL's mentioned above) to its homepage and users who wish to use the application http://order.asia.com/xyz hit it directly.

     

     

    My Requirement:

     

    I have a single new Zone created with SSL certificate assigned to it

     

    Redirect all HTTP to HTTPS to its specific URI and when I redirect http://order.asia.com/xyz

     

    it should use just one node.

     

     

    like when a client browse the 4 HTTP URL's he should be redirected to HTTPS URL for example if I browse http://order.asia.com I should get redirected to https://allinone.order.com/homepage_asia and when I hit http://order.asia.com/xyz it should get redirected to https://allinone.order.com/xyz

     

     

    Thanks & Regards,

     

    Giri

     

     

  • Hi Giri,

    You can check the host and/or URI with either if or switch statements. You can redirect the client to a new location using HTTP::redirect "http://subdomain.example.com/path/to/file.ext".

    Here is a simple example which uses both switch and if:

     
     when HTTP_REQUEST { 
      
         Check requested hostname 
        switch [string tolower [HTTP::host]] { 
           "order.asia.com" { 
              if {[HTTP::uri] starts_with "/homepage_asia"}{ 
                 log local0. "[IP::client_addr]:[TCP::client_port]: Matched order.asia.com/hompage_asia.  \ 
                    Redirecting to https://order.asia.com[HTTP::uri]" 
                 HTTP::redirect "https://order.asia.com[HTTP::uri]" 
              } else { 
                 log local0. "[IP::client_addr]:[TCP::client_port]: Matched order.asia.com.  Using pool http_pool" 
                 pool $http_pool 
              } 
           } 
           "order.aus.com" { 
              log local0. "[IP::client_addr]:[TCP::client_port]: Matched order.aus.com.  Redirecting to https://order.aus.com[HTTP::uri]" 
              HTTP::redirect "https://order.aus.com[HTTP::uri]" 
           } 
           default { 
              log local0. "[IP::client_addr]:[TCP::client_port]: Hit default clause." 
              HTTP::redirect "https://default.asia.com[HTTP::uri]" 
           } 
        } 
     } 
     

    This rule would be applied to the single HTTP VIP. I didn't try to follow your exact logic, but hopefully you can use the syntax to implement your requirements.

    If all four domains currently resolve to the same IP address, you'll need one SSL certificate which is valid for all of the hostnames. Or you'll need to change the DNS to resolve to separate IP's and use separate SSL certificates.

    Aaron