Forum Discussion
Andy_Bourke_497
Nimbostratus
Apr 20, 2009Multiple redirects on one VIP
Hi,
We have a virtual server that I've been configuring and I need to write an iRule for some specific functionality.
We have 10 regional sites that all point to one VIP. I want to have users hit the root of the website and be redirected to the application, however each region should be redirected to a different 'variable' in the uri.
Eg:
http://loc1.test.com should redirect to http://loc1.test.com/web/app/do.pl?login=auto®ion=1
http://loc2.test.com should redirect to http://loc2.test.com/web/app/do.pl?login=auto®ion=2
I think this should be fairly basic, but I'm certainly not a coder and the iRules that I have thought of have seemed pretty ugly and not very effecient.
Any pointers anyone can think of would be appreciated.
Thanks,
Andy
- hoolio
Cirrostratus
Hi Andy,when HTTP_REQUEST { Log a debug line for every request log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host][HTTP::uri]" Check if there are any digits in the host header value before a colon, saving the digits in the $digits variable if {[regexp {[^0-9:]+([0-9]+)[^0-9]*} [HTTP::host] -> digits]}{ There was at least one digit in the host header value log local0. "[IP::client_addr]:[TCP::client_port]: Matched: $digits, redirecting." HTTP::redirect "http://[HTTP::host]/web/app/do.pl?login=auto®ion=$digits" } else { There were no digits in the host header value (before a colon). Take some default action? log local0. "[IP::client_addr]:[TCP::client_port]: No match" } }
when HTTP_REQUEST { Log a debug line for every request log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host][HTTP::uri]" Redirect based on the host header value switch [HTTP::host] { "*1*" { HTTP::redirect "http://[HTTP::host]/web/app/do.pl?login=auto®ion=1" log local0. "[IP::client_addr]:[TCP::client_port]: 1" } "*2*" { HTTP::redirect "http://[HTTP::host]/web/app/do.pl?login=auto®ion=2" log local0. "[IP::client_addr]:[TCP::client_port]: 2" } "*3*" { HTTP::redirect "http://[HTTP::host]/web/app/do.pl?login=auto®ion=3" log local0. "[IP::client_addr]:[TCP::client_port]: 3" } default { This case will be hit if the request didn't have a digit in the host header value or didn't have a host header at all. HTTP::redirect "http://hardcodedhost.example.com/web/app/do.pl?login=auto®ion=default" log local0. "[IP::client_addr]:[TCP::client_port]: No match, take some default action?" } } }
- Andy_Bourke_497
Nimbostratus
Apologies - I should have explained a bit more. - hoolio
Cirrostratus
If all of the domains resolve to the ViP that the iRule is configured on, you probably want to limit the iRule by checking the requested path first. If the path equals "/", then check the requested host header value. You can add this check to the top of the iRule:when HTTP_REQUEST { Log a debug line for every request log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host][HTTP::uri]" Check if requested path is / if {[HTTP::path eq "/"}{ Redirect based on the host header value switch [HTTP::host] { "*1*" { ...
- Andy_Bourke_497
Nimbostratus
i actually just appended the uri to the switch and added the trailing / to the request - seems to have done the trick so far. dont know if it was the correct thing to do though!switch [HTTP::host][HTTP::uri] { "location.webserver.com/" { HTTP::redirect "http://[HTTP::host]/blah/blah/app/do.pl?region=R1" log local0. "[IP::client_addr]:[TCP::client_port]: Region1" }
- hoolio
Cirrostratus
Yep, that has the same effect. Checking for HTTP::path eq / before entering the switch statement should be a bit more efficient, but your method should provide the same functionality.
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