Forum Discussion

Dhruwal_Patel_2's avatar
Dhruwal_Patel_2
Icon for Nimbostratus rankNimbostratus
Mar 23, 2007

Need help for url rewrite

Hello,

 

 

I am new to iRule, so i need to clear some doubts if any one can help.

 

 

We have a scenario:

 

 

We have 2 web servers for which bigip will be balancing.

 

 

Things to acheive:

 

 

Note: $1 = remaing url with query

 

 

1) when a request comes like:

 

https://www.payment.business.com/product/$1

 

 

Then Bigip should modify that and send to webserver in this format

 

 

http://www.transaction.com/$1

 

 

Once the webserver receives this url, it will do some process and return the url like:

 

 

http://www.transaction.com/business/$1

 

 

Now BIGIP should remodify it before sending it to the browser who requested as follows:

 

 

https://www.payment.business.com/product/$1

 

 

Note: Internally servers handle different url, but for customers urls are different, and internal urls are transparent for them.

 

 

The script should work for n number of domains.

 

 

Is there any1 who can help me to script it?.

 

 

Also i am worried about, what if many users access this url at same time, then will bigip manages all the rewrite sessions?

 

 

if i am not clear, then please let me know.
  • First of all, if you are running SSL, then to manipulate the HTTP traffic, you will have to be terminating the SSL on the BIG-IP (otherwise there is no way to inspect the contents of the payload).

    1) when a request comes like:

    https://www.payment.business.com/product/$1

    Then Bigip should modify that and send to webserver in this format

    http://www.transaction.com/$1

    Assuming you are terminating the SSL, then you can easily remove sections of a string with the "string map" command.

    when HTTP_REQUEST {
       The [string map ...] command will replace all occurrances 
       of "/product" in the original HTTP::uri with an empty string
       The containing HTTP::uri command sets the URI to this new value.
      HTTP::uri [string map { "/product" "" } [HTTP::uri]]
    }

    Once the webserver receives this url, it will do some process and return the url like:

    http://www.transaction.com/business/$1

    Now BIGIP should remodify it before sending it to the browser who requested as follows:

    https://www.payment.business.com/product/$1

    I'm assuming by this you mean that embedded links in the returned content start with "http://www.transaction.com/business". There is nothing in the HTTP spec that allows a webserver to return a URL as part of the protocol. The URI is part of the HTTP Request, not the Response.

    If you do want to change all embedded links, there are several examples in the iRules CodeShare section of the wiki. The Social Security and Credit Card Scrubber examples are good places to start.

    http://devcentral.f5.com/wiki/default.aspx/iRules/CodeShare.html

    Click here

    Also i am worried about, what if many users access this url at same time, then will bigip manages all the rewrite sessions?

    This is not something to worry about. The iRules engine acts on each connection separately so there is not an issue of multiple clients causing overwrites on separate client connections.

    -Joe
  • Thanks Joe, ill come back to this, if i further run in to problems, now i have a start to work ahead.