Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Feb 03, 2010

Rewrite / redirect from /admin

I am trying to redirect and rewrite all requests to a directory, as well as any arguments that are passed through the request.

For example:

http://ourwebsite.org/admin/leads.asp?id=234&pid=193

should rewrite to:

http://legacy.ourwebsite.org//admin/leads.asp?id=234&pid=193

The following iRule below does not work - any ideas why?

 
 when HTTP_REQUEST {  
     if { ([HTTP::uri] eq "/admin*") } {  
         switch -glob [HTTP::uri] {  
              "/" { HTTP::redirect "http://legacy.ourwebsite.org" }  
              default {  HTTP::redirect "http://legacy.ourwebsite.org[HTTP::uri]" } 
         }  
     }  
 } 
 

2 Replies

  • Turns out this iRule worked instead:

     

     

    when HTTP_REQUEST {

     

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

     

    HTTP::redirect "http://legacy.ourwebsite.org[HTTP::uri]"

     

    }

     

    }
  • Hi Joe,

    You could use [HTTP::uri] starts_with "/admin" or [string match "/admin*" [HTTP::uri]] to check if the URI starts with /admin. But the * with eq is interpreted literally, not as a wildcard. Also, you can remove the switch statement as you want to include the URI for the redirect whether it's / or something longer.

     
     when HTTP_REQUEST { 
        if { [HTTP::uri] starts_with "/admin" } { 
           HTTP::redirect "http://legacy.ourwebsite.org[HTTP::uri]" 
        } 
     } 
     

    Aaron