Forum Discussion

roostar_79107's avatar
roostar_79107
Icon for Nimbostratus rankNimbostratus
Jul 02, 2009

regex irule for search url redirect

 

Any one got a sample irule that will identify a search term (in this case the word 'help') and rewrite the url using the search term?

 

 

e.g.

 

http://www.mycompany.com/forum/search!default.jspa?q=help

 

 

becomes

 

 

http://www.google.com/search?q=help site:mycompany.com/forum

 

 

thanks in advance

 

Ryan

 

2 Replies

  • Hi Ryan,

     

     

    Is the string that you want to rewrite in the response payload or in the request headers and/or request payload?

     

     

    Aaron
  • Ryan, a couple of questions come up.

    1) Are you merely looking to search for something in the URI or is there another search source?

    2) Do you want to issue a browser redirect (so the address bar on the browser get's updated) or do you want to transparently change the host and URI before it hits the server? Since you are redirecting to google.com I'm assuming you don't own google on your backend so you are looking for a browser redirect, but thought I'd ask.

    If you are just looking in the URI, you can do something like this:

     when HTTP_REQUEST {  
       switch -glob [HTTP::uri] {  
         "*help" {  
            transform url.  
         }  
       }  
     }

    For the transforming, if you want to issue a HTTP redirect, you can do so like this:

    HTTP::redirect "http://www.google.com/search?q=help site:mycompany.com/forum"

    If you want to transparently change the host and URI, here's how:

     HTTP::Header replace "Host" "www.google.com"  
     HTTP::URI "http://www.google.com/search?q=help site:mycompany.com/forum"

    Hope this helps...

    -Joe