Forum Discussion
Chris_Corsaro_1
Nimbostratus
Mar 16, 2006uri pool redirection using single domain
Hello,
I need to redirect user connections from a single domain name with different virtual server directories. I am sorry but I'm very new to iRules, so please bear with me, I am truly a newbie.
This what we need:
We need to redirect users based on a URI they enter in a browser to connect to the correct client website via an F5 Pool.
For Example User enters in :
site.domain.net/client1
redirection needs to go to pool Client1-Pool
site.domain.net/client2
redirection needs to go to pool Client2-Pool
Site.domain.net/client3
redirection needs to go to pool Client3-Pool
I need to keep adding new client pools redirections to this iRule so please keep that in mind if there are any scalability issues. How would i Create this iRule?
would it go something like this?
when HTTP_REQUEST {
set uri [HTTP::uri]
if {$uri contains "client1" } {
pool Client1-Pool
}elseif {$uri contains "client2" } {
pool Client2-Pool
}elseif {$uri contains "client3" } {
pool Client3-Pool
}
}
3 Replies
- Your iRule should work just find. You might want to make the uri lowercase before you do a comparison in case your webserver is non case sensitive.
when HTTP_REQUEST { set uri [string tolower [HTTP::uri]] if { $uri contains "client1" } { pool Client1-Pool } elseif { $uri contains "client2" } { pool Client2-Pool } elseif { $uri contains "client3" } { pool Client3-Pool } }
You might also want to use the "starts_with" operator so that you don't catch that string somewhere else in the uri (ie. http://www.foo.com/foo.bar?client1). Also, if your naming schema wraps past 10, keep in mind that /client10 will match your first comparison. Make sure you put the client10 check before the client1.when HTTP_REQUEST { set uri [string tolower [HTTP::uri]] if { $uri starts_with "/client1" } { pool Client1-Pool } elseif { $uri starts_with "/client2" } { pool Client2-Pool } elseif { $uri starts_with "/client3" } { pool Client3-Pool } }
If your iRule gets very large due to a lot of mappings, you could look into using a data group to store the mappings in and then build the logic to extract the token you want to search for from the uri and use that as a search string with the "findclass" method.
Check out the wiki for all the command help and samples.
-Joe - Chris_Corsaro_1
Nimbostratus
Thanks Joe.
I will give this a shot once we have those separate client instances up and running.
Question? : the string tolower function will convert all http requests into lower case?
Also, and this is my lack of experience in this, we have a global_ssl iRule that converts all http requests to https and sends them to our SSL pool so all connections are https.
1)Would I compile the two rules together? or
2)would i create 2 separate iRules and would I have to make the global_ssl rule take precendence?
3) Would I create the rule made above to show as HTTPS?
when HTTPS_REQUEST {
set uri [string tolower [HTTPS::uri]]
if { $uri starts_with "/client1" } {
pool Client1-Pool
} elseif { $uri starts_with "/client2" } {
pool Client2-Pool
} elseif { $uri starts_with "/client3" } {
pool Client3-Pool
}
} - Dave__Blodgett_
Nimbostratus
Joe - I work with Chris, and we have tried about a dozen different ways to get this to work. Still no success whatsoever.
What we're trying to do is pretty simple (certainly compared to some of the complex functions that Irules can handle).
We are trying to create a basic Irule that does the following:
The url http://whatever.wherever.net is set up as a virtual server on the DMZ side of the device. Let's say the address is 10.11.11.1.
On the internal side of the device, we've got, let's say, 3 nodes. Their addresses are:
10.10.10.1
10.10.10.2
10.10.10.3
Our sole objective is to route the session based on the URI, and change the protocol to SSL.
In other words, if the client hits http://whatever.wherever.net (resolves to 10.11.11.1), they should get nothing (maybe I'll have a default error page). The external listening ports should be 80 and 443.
But if they hit http://whatever.wherever.net/client1, they should be routed to 10.10.10.1:8080.
If they hit http://whatever.wherever.net/client2, they should be routed to 10.10.10.2:8080.
If they hit http://whatever.wherever.net/client3, they should be routed to 10.10.10.3:8080.
10.10.10.x:8080 is how the nodes are configured.
We'd also like to protocol to be redirected to HTTPS.
The only other caveat is that the URI might change to /client3admin or /client3report, so we'll need to use the starts with function.
So far we haven't even tried to get the SSL redirect because we can't even get the first rule to work at all, and we've tried it many different ways (we've tried countless variations of the methods described in http://devcentral.f5.com/Default.aspx?tabid=29&articleType=ArticleView&articleId=28, and no matter what, we just get a default apache error page (not found)).
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
