Forum Discussion
johns
Employee
Jul 28, 2005Using 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.
- johns
Employee
That worked well! Thanks. - johns
Employee
What 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.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 }
- johns
Employee
Actually, uRuleY's rule adds the trainling slash into the host: - 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.
- johns
Employee
Joe, 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. - unRuleY_95363Historic F5 AccountI'm not sure I understand this part of your problem:
- johns
Employee
I 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 }
- unRuleY_95363Historic F5 AccountYou could simply do something like:
if { [HTTP::uri] contains "/" } { your rule } else { whatever you would do if there was no / }
- johns
Employee
Thanks, 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 / }
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