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?
- The_Bhattman
Nimbostratus
Try thiswhen 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" } } } }
- MeAndMyBIGIP_60
Nimbostratus
awesome. that works... BUT - 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.
- MeAndMyBIGIP_60
Nimbostratus
Thanks Colin... makes sense.when HTTP_REQUEST { if {[HTTP::uri] equals {www.foo.com/bar}} {pool Bar_pool } }
when HTTP_REQUEST { HTTP::redirect https://[HTTP::host][HTTP::uri] }
- 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 } }
- 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".
- 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 } }
- MeAndMyBIGIP_60
Nimbostratus
grrr...when HTTP_REQUEST { if {[HTTP::uri] equals "/bar"} { HTTP::uri [string map {"bar" ""} [HTTP::uri]] pool bar_pool } }
when HTTP_REQUEST { HTTP::redirect https://[HTTP::host][HTTP::uri] }
- MeAndMyBIGIP_60
Nimbostratus
Okay... so here's something interesting. - 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.
http://devcentral.f5.com/wiki/Default.aspx/iRules.priority
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