Forum Discussion
Doing redirects using datagroups
Hello,
I am trying to do redirects using datagroups and getting stuck with the actual redirect using -value I have a data group called prod_domains_dg mydomain.ny1.com:=mydomain.ny1.com/1nyb mydomain.ny2.com:=mydomain.ny2.com/2nyb
I am trying to do the following
- if someone enter just https://mydomain.ny1.com then redirect to mydomain.ny1.com/1nyb and send to prod_pool
- if somecome comes with a complete link https://mydomain.ny1.com/1nyb/Status.jsp send to a prod_pool.
elseif {[class match [string tolower [HTTP::host]] contains Prod_Domains_dg ]}{ use pool Prod_pool }
this works for 2. so the domain groups is accessable and working but for 1 i am not able to replace "/" with {[class match -value [string tolower [HTTP::host]] starts_with Prod_Domains_dg ]
Any help in resolving this is appeciated. thanks
12 Replies
- Kevin_Stewart
Employee
Try this:
Data group:
mydomain.ny1.com := /1nyb mydomain.ny2.com := /2nybiRule:
when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { if { [class match [string tolower [HTTP::host]] equals Prod_Domains_dg] } { HTTP::redirect [class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg] } } }The pool, I assume, is already applied to the virtual server. So the above only redirects if the URI equals "/" and then redirects to the URI from the class match. Requests with more specific URIs are ignored.
- JPV_131616
Cirrus
check for the target for 1;
e.g.
set target [getfield [HTTP::uri] "/" 2]
then check if target == ""; if true then do the redirect to the new uri.
- What_Lies_Bene1
Cirrostratus
Can you post your if statement please. I think your issue will be the fact you are attempting to rewrite the hostname and URI.
- Net_Admin_86160
Nimbostratus
hello kevin I tried as you provided, but it is stopping at
http://mydomain.ny1.com --> https://mydomain.ny1.com/ but not going https://mydomain.ny1.com/1nyb
when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { if { [class match [string tolower [HTTP::host]] equals Prod_Domains_dg] } { HTTP::redirect [class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg] } } } - Kevin_Stewart
Employee
Ahh, I didn't get that you wanted to go to HTTPS. Try this variation:
when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { if { [class match [string tolower [HTTP::host]] equals Prod_Domains_dg] } { HTTP::redirect "https://[HTTP::host][class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg]" } } } - Net_Admin_86160
Nimbostratus
kevin,
I updated the script and yet it goes no further.
- What_Lies_Bene1
Cirrostratus
Did you also change the DG?
- Net_Admin_86160
Nimbostratus
wireshark -
GET / HTTP/1.1 Host: mydomain.ny1.com Connection: keep-alive Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Cookie: avr_2931034823_0_0_4294901760_1679819018_0=1868296818_38074561 HTTP/1.0 302 Found Location: https://mydomain.ny1.com/ Server: BigIP Connection: Keep-Alive Content-Length: 0 - Kevin_Stewart
Employee
Well, you're getting redirected, so that's something. Let's add some debug logging:
when HTTP_REQUEST { log local0. "Host equals [HTTP::host]" log local0. "Request URI equals [HTTP::uri]" if { [HTTP::uri] equals "/" } { log local0. "URI equals /" if { [class match [string tolower [HTTP::host]] equals Prod_Domains_dg] } { log local0. "Matched a data group entry: [class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg]" HTTP::redirect "https://[HTTP::host][class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg]" } } }Observe this in the LTM log from the management shell:
tail -f /var/log/ltm - Kevin_Stewart
Employee
I suspect, if this still doesn't work, that server side compression is likely causing a problem. Can you disable that for testing?
- Net_Admin_86160
Nimbostratus
Thanks Kevin , and what lies beneath - because I am blind .
this is working now
mydomain.ny1.com := /1nyb mydomain.ny2.com := /2nyb when HTTP_REQUEST { if { [class match [string tolower [HTTP::host]] equals Prod_Domains_dg] } { if { [HTTP::uri] equals "/" } { HTTP::redirect https://[HTTP::host][class match -value [string tolower [HTTP::host]] equals Prod_Domains_dg] } } if { [class match [string tolower [HTTP::host]] equals Staging_Domains_dg] } { if { [HTTP::uri] equals "/" } { HTTP::redirect https://[HTTP::host][class match -value [string tolower [HTTP::host]] equals Staging_Domains_dg] } else { use pool stagingWEBFORMS } } }- What_Lies_Bene1
Cirrostratus
You're welcome
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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