Forum Discussion
johns
Jul 28, 2005Ret. Employee
Using URI to rewrite host
I am trying to come up with a rule where the first directory name of the uri is used to rewrite the URL. an example will be:
http://www.foo.com/abc/doc/index.html =>
http://abc.foo.com/abc/doc/index.html.
I want to make it so that the rule is general enough to be applied to multiple sites like this. I am thinking I will probably have to use regex to parse up to the second "/" after the URL and store that in a variable, then constrcut URL from that. Is that possible?
Thanks.
25 Replies
- johnsRet. EmployeeThat worked well! Thanks.
You are absolutely right, I also need to replace it back to what it was orginally on the HTTP_RESPONSE. - johnsRet. EmployeeWhat I trying to do is, we have implementation with Trafficshiled Security gateway in b/w BIG-IP and the servers. The Trafficshield needs to have a unique VIP for each hostheader. So, I need to have the BIG-IP change the host to be unique for each directory (which indicates different site within the servers) and then rewrite them on the way out.
I was playing with getfield to pick up the directory after the host and set tn as a variable value just to see if I can get them to collect the right strings.when HTTP_REQUEST { set my_host [getfield [HTTP::uri] "/" 2] set my_domain [getfield [HTTP::host] "." 2] log local0. "my host is $my_host.$my_domain.com" pool ts_pool }
I just need to find a way to rewrite the URI to what it was originally on the way out. Could it be as simple as storing the original URI in a variable and replace (on the way out) the one that was rewritten on the way in?
Thanks.
John - johnsRet. EmployeeActually, uRuleY's rule adds the trainling slash into the host:
Jul 28 22:38:07 tmm tmm[739]: 01220002:6: Rule rewrite : Top level directory: aao/
Jul 28 22:38:07 tmm tmm[739]: 01220002:6: Rule rewrite : New host is: aao/ddc-f5.com - The host is not typically sent in the HTTP response headers to the client browser. If you want the browser to retain the original uri, just change the host header and the uri on the browser will not change from it's original value.
If you have urls in the response payload that you need to change back then that's another story. You'll probably want to save the original url as a global variable and then do a search and replace on the response payload.
You might want to take a look at this recent blog I posted about a recent thread regarding modifying the uri and changing the response payload.
http://devcentral.f5.com/weblogs/Joe/archive/2005/07/27/1398.aspx
Click here
-Joe - johnsRet. EmployeeJoe, you are right. Now that I think about it, there should be no need to touch the response, unless the links embedded in are absolute.
Thanks. - unRuleY_95363Historic F5 AccountI'm not sure I understand this part of your problem:
The Trafficshield needs to have a unique VIP for each hostheader.
The Trafficshield can have multiple HTTP classes on a single vip where each class catches different hosts and/or uri's and thus maps those hosts or uri's to different policies. So, I'm wondering why you would actually need to map to different VIP's since you could have different TrafficShield policies on the same VIP? - johnsRet. EmployeeI am able to get the following to work:
when HTTP_REQUEST { set my_uri [getfield [HTTP::uri] "/" 2] set client_host [HTTP::host] set new_host $my_uri.$client_host HTTP::header replace HOST $new_host log local0. $new_host log local0. $my_uri }
However, only when user puts trailing slash at the end. If not, then the server redirects with the modified URI, which does not resolve from the outside and fails. Can you help me figure out a way to add "/" if it is missing from the original request? Thanks. - unRuleY_95363Historic F5 AccountYou could simply do something like:
if { [HTTP::uri] contains "/" } { your rule } else { whatever you would do if there was no / }
Does that help? - johnsRet. EmployeeThanks, but how do I add a trailing slash to the original URI?
- bl0ndie_127134Historic F5 AccountI suspect you problem is with your 'getfield' logic. Maybe you should further change your logic to some thing like ....
set my_uri [getfield [HTTP::uri] "/" 2] if {$my_uri != "" } { your rule } else { whatever you would do if there was no / }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects