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...
unRuleY_95363
Aug 10, 2005Historic F5 Account
I'm not sure what I can say about the Javascript not working. Perhaps they have hard-coded some absolute uri's in there that are not based on the original requested uri.
As for the host, you could add a check to see if the token is already there and not add it if it is. Also, I'd move the setting of the uri/host into the if body so you are only changing it when it needs to be changed.
rule host_rewrite2 {
when HTTP_REQUEST {
set host [HTTP::host]
log local0. $host
set uri [HTTP::uri]
set token [getfield [HTTP::uri] "/" 2]
if { $token eq "" } {
log local0. "no path specified so ignore"
} else {
if { [matchclass $uri ends_with $::file_extensions] > 0 } {
log local0. "Found file request, leave as is!"
} else {
log local0. "Not a file request, update host and check for trailing slash "
if { not ( $host starts_with $token ) } {
set host "$token.$host"
log local0. "Updated host with token: $host"
HTTP::header replace "Host" $host
}
if { $uri ends_with "/" } {
log local0. "Uri ends with a slash, all's good"
} else {
log local0. "Uri doesn't end with a slash, appending one"
append uri "/"
HTTP::uri $uri
}
}
}
log local0. "host: $host"
log local0. "uri : $uri"
}
}
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