Forum Discussion

Anish_Srivastav's avatar
Anish_Srivastav
Icon for Nimbostratus rankNimbostratus
Nov 01, 2010

Need help with parsing URI

Greetings!

 

 

I have a bunch of URI's in our application like the following

 

 

http://foo.bar.com/wiki/a/b/e.html

 

http://foo.bar.com/wiki/p/q/r/s/t.html

 

http://foo.bar.com/wiki/x/y/z.html

 

 

I would like to do a redirect using iRules to eliminate the first directory "/wiki"

 

 

so if a request comes to http://foo.bar.com/wiki/a/b/e.html it should 301 to http://foo.bar.com/a/b/e.html and so on....

 

 

Can some one please help me?

 

 

Thanks,

 

Anish

 

 

2 Replies

  • Hi Anish,

    You can trim off the /wiki using string range:

    when HTTP_REQUEST {
    
        Check if URI starts with /wiki/
       if {[HTTP::uri] starts_with "/wiki/"}{
    
           Send a local redirect without the /wiki string
          HTTP::respond 301 Location [string range [HTTP::uri] 5 end]
       }
    }
    

    Aaron