Forum Discussion

metalslug2004_2's avatar
metalslug2004_2
Icon for Nimbostratus rankNimbostratus
May 19, 2015

Could someone help me with a simple redirect (iRule)?

Sorry if any of this is dumb new user stuff... I have done a bit of searching and can't find a clear answer.

 

Basically what I want to do is have anyone hitting "www.mypage.com/something" redirect to just "www.mypage.com"

 

We have some tools and services in the /something page that should not be available to the public, and until we find a better way, we want to just redirect to the root of the site. It also needs to work with https requests too.

 

I don't have very much experience with F5s so be gentle!

 

Here is what I have come up with so far:

 

when HTTP_REQUEST { if { [HTTP::path] equals "/admin" } { HTTP::redirect "/" } }

 

Any suggestions?

 

Thanks!

 

  • You might consider using a Traffic policy (if you are on TMOS 11.4 or greater) 2 Minute Tech Tip: URL Redirects

    If not then you might want to consider an iRule something like this:

    when HTTP_REQUEST {
         if { [string tolower [HTTP::path]] starts_with "/admin" } { 
         HTTP::redirect "/"
         }
         }
    

    Either way you will have to apply the traffic policy to the HTTP and HTTPS virtual server.

  • You might consider using a Traffic policy (if you are on TMOS 11.4 or greater) 2 Minute Tech Tip: URL Redirects

    If not then you might want to consider an iRule something like this:

    when HTTP_REQUEST {
         if { [string tolower [HTTP::path]] starts_with "/admin" } { 
         HTTP::redirect "/"
         }
         }
    

    Either way you will have to apply the traffic policy to the HTTP and HTTPS virtual server.

  • Looks like I'm on 10.0.1.... =(

     

    But I will give that iRule you posted a try!

     

    Thank you very much.

     

  • Another newb question. So that iRule is applied globally correct? Once i make that rule, it should take affect immediately?

     

    Also, that rule should work for both HTTP and HTTPS correct?

     

    Thanks,

     

    • Max_Q_factor's avatar
      Max_Q_factor
      Icon for Cirrocumulus rankCirrocumulus
      Yes. iRules take effect immediatly. Also since you are using a relative redirect the iRule should work for both http and https as long as the virtual server has a http profile and the https virtual server is decrypting the client side.