Forum Discussion
Feb 05, 2010
One Vs for Redirects
This should be an easy one..
I want to use one VS for a bunch of redirects, a catch all of sorts.. If for some reason this is a bad idea just let me know.
The redirect only work for the first entry, the rest fail..
when HTTP_REQUEST {
if { [HTTP::host] eq "www.firstdomain.com" } {
HTTP::redirect "http://my.firstdomain.com"
}
elseif { [HTTP::host] eq "www.seconddomain.com" } {
HTTP::redirect "http://my.seconddomain.com"
}
}
Much appreciated
43 Replies
Sort By
- Thanks guys! I think I'm close, can you show me the example with using the v9 datagroups?
- The_Bhattman
Nimbostratus
Here is one on v9 - Hmm think I'm hitting a wall here. Do you think you can work that data group into what I'm trying to do?
- hoolio
Cirrostratus
The solution Matt suggested was to create a datagroup containing the HTTP host names that the client would be making requests to. He then used string map to rewrite a static string from the requested hostname to a new value and send that new value in a redirect to the client.when HTTP_REQUEST { Log the request details and class contents. Need to use $:: to reference the class name here. log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri] with class: $::my_hosts_class" Check if the requested host is in the my_hosts_class datagroup if { [matchclass [HTTP::host] equals my_hosts_class] } { log local0. "[IP::client_addr]:[TCP::client_port]: Matched!" HTTP::redirect http://[string map -nocase {"www" "my"} [HTTP::host]][HTTP::uri] } else { HTTP::respond 200 content " Sorry, no match " log local0. "[IP::client_addr]:[TCP::client_port]: No match" } }
- Stll not working, this is the log output on it;
- hoolio
Cirrostratus
Maybe the reference to the class with $:: in the log line is breaking the matchclass command? Can you remove this portion of the log line: - Thanks for the quick reply!
when HTTP_REQUEST { Log the request details and class contents. Need to use $:: to reference the class name here. log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]" Check if the requested host is in the my_hosts_class datagroup if { [matchclass [HTTP::host] equals my_hosts_class] } { log local0. "[IP::client_addr]:[TCP::client_port]: Matched!" HTTP::redirect http://[string map -nocase {"www" "my"} [HTTP::host]][HTTP::uri] } else { HTTP::respond 200 content " Sorry, no match " log local0. "[IP::client_addr]:[TCP::client_port]: No match" } }
- Sorry that time I tested it looked like I had the hostnames on seperate lines in the data group, they're back to being on one line, log looks the same...
- hoolio
Cirrostratus
You'll want each hostname on a separate line in the datagroup. - hoolio
Cirrostratus
Or maybe it's this known issue in 9.4.x?
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