Forum Discussion

Venkat_96085's avatar
Venkat_96085
Icon for Nimbostratus rankNimbostratus
Apr 24, 2009

URL Redirection

Hi friends,

 

 

I am a newbie to iRules and neither a coder. i have the following scenario and i need irules for this.

 

 

When some user connects to a URL say example: www.xyz.com the user has to get redirected to www.xyz.com/search/home.asp

 

 

Similarly when somebody connects to a URL www.xyz.com/fslink the user has to get redirected to www.xyz.com/search/home.asp

 

 

Appreciate if you can send me the iRules for the above.

 

 

Thanks,

 

Venkat
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi Venkat,

    You can use HTTP::redirect command (Click here) to redirect the client. You would want to check if the request was to the root document (/) or fslink before redirecting:

     
     when HTTP_REQUEST { 
      
         Check if request is to / or /fslink 
        switch [string tolower [HTTP::path]] { 
      
           "/" - 
           "/fslink" { 
      
               Redirect client 
              HTTP::redirect "http://www.xyz.com/search/home.asp" 
           } 
        } 
     } 
     

    If you want the client to not see the change in the path, you could rewrite the URI using HTTP::path (Click here).

    Aaron
  • Hi Aaron,

     

     

    Thanks for your reply. i made little bit of modifications to the iRules can you tell me if this is correct.

     

     

    1. When somebody connects to www.xyz.com, he gets redirected to www.xyz.com/index.html

     

     

    2. when somebody connects to www.xyz.com/fslink, he gets redirected to www.xyz.com/search/home.asp

     

     

    3. when somebody connects to www.xyz.com/doc, he gets redirected to www.xyz.com/doc.html

     

     

    Can you tell me if the below irules are correct. Thanks for your help.

     

     

    when HTTP_REQUEST {

     

     

    Check if request is to / or /fslink

     

    switch [string tolower [HTTP::path]] {

     

     

    "/" {

     

    HTTP::redirect "http://www.xyz.com/index.html"

     

    }

     

    "/doc" {

     

    HTTP:: redirect "http://www.xyz.com/doc.html"

     

    }

     

    "/fslink" {

     

     

    Redirect client

     

    HTTP::redirect "http://www.xyz.com/search/home.asp"

     

    }

     

    }

     

    }