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
- Sorry I haven't been back sooner, been terribly ill..
Do you mean each pair or for every hostname?
ex 1;
www.my.domain.com www.domain.com
ex 2
www.my.domain.com
www.domain.com
In any event I tried it both ways, still not working..
Ahhh I made an error, our GTMs are on 9.4.8...
The LTMs in questions are on;
BIG-IP Version 9.3.1 58.0
Hotfix HF4 Edition
Sorry about that..
I suppose this changes things..
Here is the b class my_hosts_class list output;
class my_hosts_class {
"www.my.domain.com"
"www.domain.com"
}
thanks - 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.
For 9.3.x (actually anything below 9.4.4), you'd need to reference the class with the $:: prefix: $::my_hosts_class.
Aaron - OKay gotcha....
So I did a b load, and we're getting closer! Now it's actually envoking the irule, but It keeps getting no Match
log;
16:36:46 tmm tmm[1144]: Rule VSred : 208.125.68.x:1493: GET to www.my.domain.com/
Mar 1 16:36:46 tmm tmm[1144]: Rule VSred : 208.125.68.192:1493: No match
Now, for s&Gs, I removed the second domain in the line, aka the "my.domain.com", where i want it to go.. so it was just www.my.domain.com and I get a "Matched!" in the log...
So when adding them in one line it's trying to match the whole line... ideas?!?! - 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.
Can you try adding each hostname to the datagroup on a separate line?
Aaron - Ah no problem..
class my_hosts_class {
"my.domain.com"
"www.my.domain.com"
}
Still not working...
in IE, I get nothing, and in firefox it actually tries redirecting to my.x.xDomain.com.... huh??? Where the heck is it getting that from?
In any event I was wondering if the my_hosts_class was backwards... so I tried entering them in the datagroup differently, but everytime I run a b class my_hosts_class list I still see them in the same order...?? - 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]
Thanks,
Aaron - 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...
Basically the iRule needs to be able to mach the first url, whether it be www.www.www.domain.com or you.me.her.domain.edu or .domain.com etc etc and redirect to a specific url, whether it be .domain.com or www.domain.com or gmail.google.com, or a.b.c.domain.com anything...
Anyways, here is my output with the new log, i've used different domain names to try and make it a little less confusing...
So my output of the class;
class my_hosts_class {
"health.google.com"
"www.health.google.com"
}
Here is the output from the log...
Mar 2 09:13:07 tmm tmm[1144]: Rule VSred : 69.37.2.138:51581: GET to www.health.google.com/
Mar 2 09:13:07 tmm tmm[1144]: Rule VSred : Matched. Redirecting to: http://my.health.google.com/
See what happened here, instead of redirecting to health.google.com it redirected to my.health.google.com... at first I thought the string map -nocase was there to make sure the rule caught if someone put a cap WWW/MY... but I see it's there to actually prepend www or my to the url... remember I don't want to focus on any one name... I just want to match any url and redirect to another, don't focus on what I'm actually using for a records... - 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" } }
It works for now, but it's not what i'm looking for... that locks us into specifically stripping www. from the url.. my goal is to detect any url and redirect to any url.. maybe we have to go at the irule differently?
also stacking urls works in the datagroup.. but I was under the impression the datagroup was being used to detect the url and specify the new url to redirect to... not the case... it's used to detct urls..
Thanks for all the help!!
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
