Forum Discussion

DaveC_53879's avatar
DaveC_53879
Icon for Nimbostratus rankNimbostratus
May 26, 2011

Need help with a URL re-write

I need an iRule to look for "foldername" in the URL below,

 

 

http://web.com/foldername/tap/?empid=00000000

 

 

and then re-write to the URL below, removing "foldername" completely. The first URL may be HTTP or HTTPS.

 

 

https://newsub.newdomain.org/tap/?empid=00000000

 

 

Everything after "foldername" can be different and needs to stay as is, but this is the typical format. I only want to change URLs that contain the word "foldername".

 

 

I know how to remove /foldername, and how to re-write to the new URL, but not how to do both simutaneously. I tried 2 rules, 2 steps, but that didn't work and I can't get the format right to do it all in one rule.

 

 

I appreciate any and all help.

 

 

Dave

2 Replies

  • Hi Dave,

    I think something like this should work:

    
    when HTTP_REQUEST {
       if {[HTTP::path] starts_with "/foldername"}{
          HTTP::redirect "https://newsub.newdomain.org[string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end]"
       }
    }

    You can add debug logging to check the values for [string first "/" [HTTP::uri] 1] and [string range [HTTP::uri] [string first "/" [HTTP::uri] 1] end] to see how it works. The idea is that you get the first / after the first character in the URI and then read from that to the end of the original URI to determine the URI for the redirect.

    Aaron