Forum Discussion

Puneet_73909's avatar
Puneet_73909
Icon for Nimbostratus rankNimbostratus
Jun 26, 2009

Wildcard redirection

Hi I am trying to write an irule but unable to do so. SEEK HELP

 

 

This one works:

 

 

when HTTP_REQUEST {

 

if {([string tolower [HTTP::path]] ends_with "/doc")} {

 

HTTP::redirect "http://[HTTP::host]/nmhomepage.jsp"}}

 

 

 

I want if user type www.xyz.com/doc/blablah then it redirects to

 

 

HTTP::redirect "http://[HTTP::host]/nmhomepage.jsp"

 

 

 

Please help me to write an redirect rule.

 

 

Puneet

4 Replies

  • Hi Puneet,

    Then you can write it like the following

     
     when HTTP_REQUEST { 
         if {([HTTP::host] eq "www.xyz.com) and ([HTTP::uri] eq "/doc/blahblah") } { 
            HTTP::redirect "http://[HTTP::host]/nmhomepage.jsp" 
           } 
     } 
     

    I hope this helps

    CB

  • CM,

     

    Thanks for your help...

     

    when HTTP_REQUEST

     

    {if {([HTTP::host] eq "www.xyz.com) and ([HTTP::uri] eq "/doc/blahblah")}

     

    { HTTP::redirect "http://[HTTP::host]/nmhomepage.jsp"}}

     

    But this is not working....I want to use wild character after /doc/*

     

    I don't know what user will type after "doc", so I want to match "www.xyz.com/doc" and it will redirect to specific page. Here * can be anything. I tried many options but not working.

     

    Appreciate if you can help me with this.
  • You can use starts_with for a logical wildcard at the end of /doc*:

     

     

    ([HTTP::uri] starts_with "/doc/")

     

     

    Or you could use string match for glob style wildcard pattern matching:

     

     

    (string match "/doc/*" [HTTP::uri])

     

     

    Aaron