Forum Discussion

Jovanny_Basilio's avatar
Jovanny_Basilio
Icon for Nimbostratus rankNimbostratus
Mar 15, 2010

Simple URL redirect

I have a need for a simple iRule that will redirect based on url...to put it simple I am trying to redirect

 

 

domain.com ---> to www.domain.com

 

domain.com/abc ---> www.domain.com/abc

 

domain.com/user ---> www.domain.com/user

 

 

fairly straightforward, currently just have a simple redirect rule to that forwards any http request to www.domain.com, would like to know include these particular paths. Thanks.

 

 

 

-J
  • This one should do what you are looking for:

     
     when HTTP_REQUEST { 
     HTTP::redirect "http://www.[HTTP::host][HTTP::uri]" 
     } 
     

  • You'd want to check to make sure that the www. wasn't submitted:

     
     when HTTP_REQUEST { 
       if { [HTTP::host] eq [domain [HTTP::host] 2] } { 
         HTTP::redirect "http://www.[HTTP::host][HTTP::uri]" 
       } 
     } 
     

  • Good point Citizen, if you don't, you'll be redirecting to www.www.domain.com, if indeed you're using the same VS in dns...

     

     

    If your only purpose is to check for "www" and add it if it's missing that will work perfect..

     

     

    If you want to specify the exact url and redirect, explore findclass and classes