Forum Discussion

dacrud_18985's avatar
dacrud_18985
Icon for Nimbostratus rankNimbostratus
Sep 16, 2008

remove everything after question mark

Hi all,

 

 

I have a URL like so:

 

 

http://www.domain.com/popular_stuff/list/5?id_session=BLAHBLAHBLAHBLAH

 

 

and I need to strip everything after the question mark and only return the path of the URL like this (in the body of the html):

 

 

/popular_stuff/list/5

 

 

Would this work:

 

 

rule strip_question {

 

when HTTP_REQUEST {

 

if { [HTTP::uri] contains "/popular_stuff/list"} {

 

HTTP::respond 200 content "[HTTP::path]"

 

}

 

}

 

}

4 Replies

  • Do you want to redirect the client with the updated path-only location or do you want to rewrite it before the request is sent to the pool? Do you want to do this with all requests that contain a query string?

    With a redirect, the browser's address bar will show the update. With a rewrite it will not be modified. Here are two examples:

    Rewrite:

      
      when HTTP_REQUEST {  
        
          Check if there is a query string in the URI  
         if {[string length [HTTP::query]]}{  
        
             Rewrite the URI to remove the query string  
            HTTP::uri [HTTP::path]  
         }  
      }  
      

    Redirect:

       
      when HTTP_REQUEST {  
        
          Check if there is a query string in the URI  
         if {[string length [HTTP::query]]}{  
        
             Redirect the client to the same host and the path (URI without the query string)  
            HTTP::redirect http://[HTTP::host][HTTP::path]  
         }  
      }  
      

    For more info on the commands, you can check the iRules wiki pages:

    HTTP::path (Click here)

    HTTP::uri (Click here)

    HTTP::redirect (Click here)

    Aaron
  • No, I need to respond with 200 content. I believe I've got it.. thanks for the help!
  • If you do want to send back a response with the requested path in the payload, the rule you posted originally should work. Was there something not working with that?

     

     

    Aaron