Forum Discussion

Govin_48123's avatar
Govin_48123
Icon for Nimbostratus rankNimbostratus
May 12, 2008

Masking the URI and also redirecting!

Hi Gurus,

 

Below is the scenarios I am trying to implement, and need some help,

 

 

Case 1)User Types in http://www.site.com/, the application server basically does a 301 redirect to http://www.site.com/home. What I am trying to implement is instead of the appserver doing the redirect I want to handle that at the F5,

 

http://www.site.com/ should be redirected to http://www.site.com/home with 200 response code and the address bar should show http://www.site.com/

 

Case 2)User Types in http://www.site.com, I want to redirect to http://www.site.com/ with 301 response code which then follows through case1).

 

Case 3) User types in http://www.site.com/home then the Client gets response directly form the appserver, Irule doesnt need to handle this at all.

 

 

Below is the Irule that I have but its not perfect,The Uri doesnt get masked)Can you tell me what I am missing!

 

Thanks

 

-G

 

 

Irule:

 

 

 

when HTTP_REQUEST {

 

set uri [HTTP::uri]

 

if { $uri equals "/" } {

 

HTTP::respond 301 Location "http://site.com/home"

 

}

 

elseif { $uri equals "" } {

 

HTTP::respond 200 Location "http://site.com/"

 

}

 

 

}

 

6 Replies

  • A few comments:

    - if a client types in www.example.com (without any path), the browser will append a forward slash to the URL (http://example.com) and the path will be "/"

    - if you send a redirect to the client with a 30x status, the browser will make a request to the Location header value

    - if you send a 20x response to the client, the client will ignore any Location header value as it's not an expected header

    It sounds like you just want to redirect clients who request the root document to /home and send all other requests to the VIP's default pool. If that's the case, this rule should work for you:

      
     when HTTP_REQUEST { 
      
        if {[HTTP::path] eq "/"}{  
           HTTP::respond 301 Location "http://site.com/home"  
        }  
     }  
     

    Aaron
  • How about this?

    when HTTP_REQUEST { 
       if { [HTTP::uri] equals "/" } { 
         HTTP::uri "/home" 
       } 
     }

    I think this satisfies all your criteria.

    1. for http://www.site.com/, URI is converted from "/" to "/home" and sent to the backend server. The browser doesn't need a redirect for this and the address bar stays the same (http://www.site.com)

    2. There will never be a request of (http://www.site.com), as hoolio mentioned, the browser will append a slash to empty URIs, so the URI will always be at a minimum a slash.

    3. All other URI's are left alone and sent as is to the backend servers.

    -Joe
  • Thanks Joe and Hoolio for the replies! I understand now that the browser appends a / even when the URI is "".

     

    That doesnt address the URI masking issue. How do I get the URI to be "/" even though its redirected to /home?

     

    Thanks,

     

    G
  • My solution is not a redirect. It changes the URI on the LTM before it gets to your app server. The browser requested "/", the LTM changed it to "/home" and the webserver received it as "/home". Everyone is happy!

     

     

    -Joe