Best way to rewrite no redirect

All,

I’ve got an application that needs to re-write the url…not redirect. There is data being posted…so a redirect would lose the data.

So…

when HTTP_REQUEST {

if { [HTTP::uri] contains “/specificfile.asp/” } {

? - but not a redirect…

Any suggestions?

Thanks,

Jim

maco0720

Hi Jim,

You can use HTTP::uri (Click here) or HTTP::path (Click here) to rewrite the URI or path.

You can check the HTTP::path wiki page for a description of the difference between the two commands.

Aaron

Aaron,

Thanks for the answer…unfortunately…I didn’t explain myself well. So here’s a better description.

I need to rewrite the entire url…based on the specific file in the URI.

So:

when HTTP_REQUEST {

if { [HTTP::uri] contains “/specificfile.asp/” } {

I need to change the url to one value as opposed to

if { [HTTP::uri] contains “/differentfile.asp/” } {

changes to a different url.

if

Fairway.com | Fairway Independent Mortgage Corp, NMLS ID 2289 send to http://www.away.com/whatever.asp

elseif

Fairway.com | Fairway Independent Mortgage Corp, NMLS ID 2289 sent to http://www.here.com/another.asp

So I’ve got to rewrite the incoming url to two totally different urls based on the file requested…but cannot redirect.

Thanks again,

Jim

So am I asking a question that has been covered a lot and I should be searching better for the answer (can’t seem to find anything that matches)…or is this not possible in everyone’s opinion.

Thanks,

Jim

maco0720

Hi Jim,

I just missed your reply last week. If you want to check the host value, you can use HTTP::host (Click here). To rewrite the Host header value, you can use ‘HTTP::header replace Host “newhost.example.com”’ (Click here). To get/set the URI, you can use HTTP::uri (Click here).

So to rewrite the host and URI without the client seeing the change, you can use an iRule like this:

when HTTP_REQUEST { 

    log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host][HTTP::uri]" 

     Check host/uri (set to lowercase) 
    switch "[string tolower [HTTP::host][HTTP::uri]]" { 

       "www.home.com/specificfile.asp" { 

           Rewrite host/URI 
          HTTP::header replace Host "www.here.com" 
          HTTP::uri "/whatever.asp" 
          log local0. "[IP::client_addr]:[TCP::client_port]: Rewrite host/uri (1)" 
       } 
       "www.home.com/differentfile.asp" { 

           Rewrite host/URI 
          HTTP::header replace Host "www.here.com" 
          HTTP::uri "/another.asp" 
          log local0. "[IP::client_addr]:[TCP::client_port]: Rewrite host/uri (2)" 
       } 
    } 
 } 


 Aaron

Hoolio…That helped alot…thanks. I’m still working on it…but will post the end result when the testing is done.

Thanks again!!!

Jim