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
- Sorry I haven't been back sooner, been terribly ill..
- hoolio
Cirrostratus
If you're using the rule you posted in this reply (Click here), you're checking to see if the requested host is in the datagroup and then replacing www with my in a host header rewrite. So you would want to list all of the hostnames that you want to rewrite from www to my in the datagroup on a single line. - OKay gotcha....
- hoolio
Cirrostratus
Sorry, I wrote the exact opposite of what I meant to say. You'd want to list all of the hostnames that you want to rewrite from www to my in the datagroup all on separate lines--not on a single line. - Ah no problem..
- To be clear, it is matching in the log... just seems not to be redirecting properly... and actually redirecting to my.x.x.com..?? very odd..
- hoolio
Cirrostratus
Can you post more exact samples of the original and redirected domains? It might help to log the value being redirected to:log local0. "Matched. Redirecting to: http://[string map -nocase {"www" "my"} [HTTP::host]][HTTP::uri]" HTTP::redirect http://[string map -nocase {"www" "my"} [HTTP::host]][HTTP::uri]
- Okay trying now, so our rule looks like this now;
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. "Matched. Redirecting to: http://[string map -nocase {"www" "my"} [HTTP::host]][HTTP::uri]" 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" } }
- Okay I think I see what's going on here.. I was only using "my" and "www" as an example for the A records... I don't actually want to always use or replace "my" or "www", the two A records (or a record and subdomain, however you want to think of them as) should be able to be anything before the domain...
- Okayy first success, after figureing out what the string map was actually doing I re-wrote the rule like this;
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. "Matched. Redirecting to: http://[string map -nocase {"www." ""} [HTTP::host]][HTTP::uri]" HTTP::redirect http://[string map -nocase {"www." ""} [HTTP::host]][HTTP::uri] } else { HTTP::respond 200 content " Sorry, no match " log local0. "[IP::client_addr]:[TCP::client_port]: No match" } }
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