Forum Discussion
marcus_lindner_
Nimbostratus
Jan 11, 2006uri rewrite based on the servername
I am trying to come up with a rule where the server name of the uri is used to rewrite the URL. an example will be:
http://server_1.de/index.html <=> http://server_4.de/server1/index.html
http:/...
Jan 11, 2006
For redirects based on contents in the URI, you can do it all from within the HTTP_REQUEST event.
Here's one way to do it.
when HTTP_REQUEST {
set
if { [HTTP::host] ends_with "server_1.de" } {
HTTP::redirect "http://server_4.de/server1[HTTP::uri]"
} elseif { [HTTP::host] ends_with "server_2.de" } {
HTTP::redirect "http://server_4.de/server2[HTTP::uri]"
} elseif { [HTTP::host] ends_with "server_3.de" } {
HTTP::redirect "http://server_4.de/server3[HTTP::uri]"
}
pool zone_xml_gw
}This will look for the host portion of the URI and then issue the redirects. I've used the ends_with operator as opposed to the eq operator so that all requests to that domain are supported (www.server_1.de, etc). If you don't care about this then switch back to the eq operator.
A slightly more optimized version (using a switch instead of if/elseif) would be something like this:
when HTTP_REQUEST {
switch -glob [HTTP::host] {
"*server_1.de" {
HTTP::redirect "http://server_4.de/server1[HTTP::uri]"
}
"*server_2.de" {
HTTP::redirect "http://server_4.de/server2[HTTP::uri]"
}
"*server_3.de" {
HTTP::redirect "http://server_4.de/server3[HTTP::uri]"
}
}
pool zone_xml_gw
}If you are needing to support many more hosts then it might make sense to use a data group in conjunction with the findclass command. A search of the forum on findclass should show you multiple examples.
Hope this helps...
-Joe
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
