Forum Discussion
MeAndMyBIGIP_60
Nimbostratus
Sep 02, 2009Nesting a redirect to another pool?
So I have an existing HTTP > HTTPS redirect rule running fine that's running on Pool1:
when HTTP_REQUEST {
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
I have another, Pool2, that I'd like to make visible without having to get another firewall hole & external IP going
Pool 1, site https://www.foo.com
Pool 2, site http://www.bar.com
Would like to have http://www.foo.com redirect to https://www.foo.com (this runs fine)
Would also like to have http://www.foo.com/bar redirect to http://www.bar.com
I had tried
when HTTP_REQUEST {
HTTP::redirect https://[HTTP::host][HTTP::uri]
if {[HTTP::uri] equals {www.foo.com/bar}} {pool Bar_Pool}
}
}
but i get 404 errors, presumably because there is no "/bar" folder on the Bar_Pool servers
can I do this somehow?
11 Replies
- The_Bhattman
Nimbostratus
Try this
Where the default pool VIP:80 is pool 2 and default pool for VIP:443 is pool 1
This code would be applied on VIP:80when HTTP_REQUEST { if { ([HTTP::host] eq "www.foo.com") } { switch -glob [HTTP::uri] { "/" { HTTP::redirect "https://[HTTP::host]" } "/bar" { HTTP:redirect "http://www.bar.com" } } } }
This assumes that www.bar.com is hosted on the VIP:80
Hope this helps
CB - MeAndMyBIGIP_60
Nimbostratus
awesome. that works... BUT
I neglected to mention that the pool2:80 nodes for www.bar.com are backend-only servers that aren't visible externally.
So the re-direct part is working, but maybe I should have asked the question to differently, maybe it should have been "re-route the traffic"
Current traffic for http://www.foo.com/ gets redirected to https://www.foo.com/ on the backend server nodes in Pool1
Would like to have http://www.foo.com/bar re-route to the backend server nodes in Pool2 (basically this is a staging site that lives on a pool of 2 non-production servers that we'd like to make visible to customers for design review)
So the URL they would hit (http://www.foo.com/bar) points to http://backend_pool2/
does that make any sense? - Colin_Walker_12Historic F5 AccountSo for your above needs you'd want to either change the redirect to point to whatever the appropriately routable internal hostname is for the location of the new content, or you'd want to use the pool command instead, if there is no routable hostname to use with the redirect command.
Does that make sense?
Colin - MeAndMyBIGIP_60
Nimbostratus
Thanks Colin... makes sense.
As I'm not routable to the back-end, taking the Pool tack:when HTTP_REQUEST { if {[HTTP::uri] equals {www.foo.com/bar}} {pool Bar_pool } }
But I'm getting redirected to https://www.foo.com/bar and then :
404 NOT FOUND
This irule is set to run AFTER the above:when HTTP_REQUEST { HTTP::redirect https://[HTTP::host][HTTP::uri] }
What am I missing (sorry... new to iRules)?
thanks for your help!! - L4L7_53191
Nimbostratus
Maybe something like this?when HTTP_REQUEST { if {[HTTP::uri] equals {www.foo.com/bar}} { HTTP::uri [string map {"bar" ""} [HTTP::uri]] pool Bar_pool } }
-Matt - One glaring problem is that "www.foo.com" is not contained in [HTTP::uri]. The format is http://[HTTP::host][HTTP::uri]. You'll either need to change the left side of the comparison to "[HTTP::host][HTTP::uri]" equals ... or the second to ... equals "/bar".
-Joe - L4L7_53191
Nimbostratus
Wow I got so focused on showing how string map may help that 404 I spaced the [HTTP::host] bit - thanks for the catch. At any rate, it may help to yank 'bar' from the URI if that's causing the issue on the backend. Something like:when HTTP_REQUEST { if {[HTTP::uri] equals "/bar"} { HTTP::uri [string map {"bar" ""} [HTTP::uri]] pool Bar_pool } }
-Matt - MeAndMyBIGIP_60
Nimbostratus
grrr...
Matt - yours isn't quite doing it.
http://www.foo.com/bar resolves to https://www.foo.com/
thought maybe it was the HTTPS, but
https://www.foo.com/bar resolves to itself, with 404 NOT FOUND
I thought maybe it was that nothing existed at http://backend_pool2/bar, maybe I needed to put something there, so I created a site there, but that didn't change anything
Is it feasible to point a [HTTP::host][HTTP::uri] to a Pool? or do I need to create a Virtual Server for [HTTP::host][HTTP::uri] to point to?
Once again, here's what I'm trying to do:
[HTTP::host] resolves to https://www.foo.com using a standard iRule to redirect HTTP to HTTPS, and content is served by Virtual Server nodes in Pool1
[HTTP::host][HTTP::uri] when uri = "/bar" should resolve to content served by nodes in Pool2
the iRules I have running (in order) are:
iRule 1when HTTP_REQUEST { if {[HTTP::uri] equals "/bar"} { HTTP::uri [string map {"bar" ""} [HTTP::uri]] pool bar_pool } }
iRule2when HTTP_REQUEST { HTTP::redirect https://[HTTP::host][HTTP::uri] } - MeAndMyBIGIP_60
Nimbostratus
Okay... so here's something interesting.
I removed the HTTP > HTTPS redirect iRule, it kinda works.
I get prompted for credentials, but then my URL becomes
http://www.MACHINENAME.com/bar/SitePages/Home.aspx
so not quite sure how that [HTTP:HOST] value (www.node1_machinename.com) is getting there, and also I was hoping the [HTTP:URI] would be just "/" not "/bar"
and of course, the HTTP > HTTPS redirect is gone - Ok, let's take a step back. You are just changing the URI with the HTTP::uri as it's presented to the backend server. This is not the same as a full HTTP::redirect that sends the response back to the browser with a new URL to request and thus changes the address bar.
I'm still a bit confused at what you want to do. I'm not sure if you want to map "/bar" in the URI to nothing but only if it's just "/bar" and not "/bar/index.html" or something like that. If you could give us a list of input's and outputs it will be easier to come up with a working solution for you.
ie.
http://www.foo.com/bar -> http://www.foo.com/
http://www.foo.com/bar/index.html -> http://www.foo.com/index.html
http://www.foo.com/foobar -> http://www.foo.com/foobar
http://anything -> https://anything
Also, we need to know whether you want full redirects or just want to trick the backend server into "thinking" the direct was from the new URI. This will determine whether we issue a HTTP::redirect or just manipulate the HTTP::uri.
Also, If you want to include the http->https iRule, you'll likely want to set a priority on them to make sure they are executed in the order you expect. If you don't have SSL termination and the URI mapping iRule running on the SSL virtual, then that iRule won't execute if the http->https redirect is processed first. See the documentation on "priority" for details on how to use it:http://devcentral.f5.com/wiki/Default.aspx/iRules.priority
Click here
Hope this helps...
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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