Forum Discussion

Mike_Graston_10's avatar
Mike_Graston_10
Icon for Nimbostratus rankNimbostratus
Jul 13, 2007

Simple Base URl rewrite

OK I have been looking at this forum and I know it's here somewhere but can't find it. My issue is I have a proxy server sitting in front of a web site http:///abc.com. I need to rewrite the url going to the proxy to http://def.com. send it to my proxy pool in my VS. then on it;s reverse path back to the client rewrite the base url back to http://abc.com. Of course this is all while keeping the uri portion in tact.

 

I think I am on the right track with this script but it is puzzing on the return trip.

 

 

when HTTP_REQUEST {

 

set userhost [HTTP::host]

 

if { $userhost == "abc" } {

 

set userhost " def "

 

}

 

 

any help would be appreciated.

7 Replies

  • You are on the right track with retrieving the value with HTTP::host but you are just updating a local variable, not the actual host header that is sent. This should work for you.

    when HTTP_REQUEST {
      if { [HTTP::host] eq "abc.com" } {
        HTTP::header replace "Host" "def.com"
      }
    }

    That's it. There is nothing needed to be done on the return trip to the browser because the browser still thinks it's accessing http://abc.com. That, along with the fact that the URI isn't part of the HTTP response so even if you wanted to, you couldn't inform the browser of the backend switch. The only way to make a browsers address bar change to an updated URI (ie, if you wanted it to display http://def.com) is to issue a HTTP redirect causing the browser to reissue a new request to the updated address.

    -Joe
  • Thanks for the quick reply. I definately do not want the browser to know they are going to def as they couldn't resolve it anyway but if there is a link within the web stie to another page I assume they would click and the request would send the browser to the real url def. In this case the traffic being sent back ot the user would have the def in it and the browser wouldn't know what to do with it? Am I correct or am I just confusing myse3lf here?
  • xf,

     

     

    That would only really happen if the server puts in a reference that explicitly says: http://def.com/someresource.html.

     

     

    Typically, the html is just the resource and so they will look like:

     

     

    img src="/path/picture.gif"

     

     

    Such references will have the hostname portion supplied by the browser (which thinks it is going to abc) and so it all should work.
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    The webserver could be sending absolute URLs (http://def.com/path/file) or relative URLs (/path/file). Or both.

     

     

    Examine the page source returned by the server (View Source in your browser) and search for the hostname "def.com". If you find it, the server is sending absolute URLs and you can use a stream profile to replace "def.com" with "abc.com"

     

     

    /d
  • Ok.

     

     

    Now I am more confused then ever. If I use the stream profile do I need to continue the Irule and am I even in the right forum to discuss this any further?

     

    I am not sure as my loggin is not working the Irule is working or not.
  • actually has anyone enabled a stream within an irule. I found an example on f5's web site of all places???

     

     

    when HTTP_RESPONSE {

     

    STREAM::enable

     

    STREAM::expression "@123@ @abc@"

     

    }

     

     

    I still can't log and not sure what the syntax would be to log this????

     

     

    any help would be appreciated.
  • Ok, for anyone following this I have successfully done this. I set up a stream profile and changed abc to def within the header. I also needed to setup a http profile set to rechunk then added an irule for the response going back to the browser so the user dos not know he is hitting a different url.

     

    when HTTP_RESPONSE {

     

    STREAM::enable

     

    STREAM::expression "@abc@ @def@"

     

    }

     

     

    Whast also would probably work is 2 Irules one for the requst when HTTP_REQUEST

     

    { if { [HTTP::host] eq "abc.com" } { HTTP::header replace "Host" "def.com"

     

    }

     

    }

     

    then one for the response:

     

     

    when HTTP_RESPONSE {

     

    STREAM::enable

     

    STREAM::expression "@abc@ @def@"

     

    }

     

     

    Thanks for all the help.