Yet another URI rewrite

With our company divesting, I’ve been tasked with identifying incoming remote_addr, then intercepting certain URI content and modifying that URI on the fly.

Example: http://www.abc.com/com/usa/wheretogo

identify the com/usa and change it to com/usanew with any prepended or appended URI content remaining the same.

Result: http://www.abc.com/com/usanew/wheretogo

I’m using a Data Group to identify the affect remote_addr, but not sure how to identify the specific URI content and replace it on the fly.

Kevin

Hi Kevin,

You can rewrite the URI with HTTP::uri and the path with HTTP::path. Here is an example:

when HTTP_REQUEST { 
  
      Datagroup check loigic goes here 
    ... 
  
     Check if path starts with /com/usa/ 
    if {[HTTP::path] starts_with "/com/usa/"}{ 
  
        Replace /com/usa/ with /com/usanew/ in the path 
       HTTP::path [string map {/com/usa/ /com/usanew/} [HTTP::path]] 
    } 
 }

Aaron

Thanks for the info…adding to the question…

What if you also wanted to add a redirect into the situation?

Example:

redirect http://abc.com to http://xyz.com and also change the path as noted above.

-Thanks!

You can change HTTP::path to HTTP::redirect. You’re supposed to use a fully qualified URL in a redirect, but all browsers support a local one (URI without a protocol or domain name).

Aaron

Hoolio, well done! Works great.

Kevin