Forum Discussion
sstafford
Nimbostratus
Jul 30, 2008string based https redirect
Hi all--yes I'm new.
Have a customer that needs a specific page or two forced to https when requested by a client. After poking around some, I came up with
when HTTP_REQUEST {
Check for given string and redirect if found
if {[HTTP::uri] contains "alumni/giving/gift/"}{
HTTP::respond 301 Location "https://[getfield [HTTP::host] : 1][HTTP::uri]"
}
}
which I think will work, at least for the string above. I also assume there's some sort of "logical or" that I can add so that multiple strings can be controlled by a single iRule?
Thanks
6 Replies
- sstafford
Nimbostratus
Ok, I've updated after more reading--also, I've switched to the "ends_with" operator. Will this work?
when HTTP_REQUEST {
Check for given string and redirect if found
if {[HTTP::uri] ends_with "alumni/giving/gift/"}{
HTTP::respond 301 Location "https://[getfield [HTTP::host] : 1][HTTP::uri]"
} elseif { [HTTP::uri] ends_with "alumni/giving/pledge/" } {
HTTP::respond 301 Location "https://[getfield [HTTP::host] : 1][HTTP::uri]"
} elseif { [HTTP::uri] ends_with "alumni/directory/search.aspx" } {
HTTP::respond 301 Location "https://[getfield [HTTP::host] : 1][HTTP::uri]"
} elseif { [HTTP::uri] ends_with "alumni/directory/update.aspx" } {
HTTP::respond 301 Location "https://[getfield [HTTP::host] : 1][HTTP::uri]"
} - Patrick_Chang_7Historic F5 AccountYou are missing a closing } in the iRule, but other than that, I believe it will do what you want.
- Here is another way to go about it with a wildcard switch and it will perform a bit better than all of the comparisons above:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "*alumni/giving/gift/" - "*alumni/giving/pledge/" - "*alumni/directory/search.aspx" - "*alumni/directory/update.aspx" { HTTP::respond 301 Location "https://[getfield [HTTP::host] : 1][HTTP::uri]" } } }
I also threw in a "string tolower" in the comparison string so that you would catch all case options (since you seem to be using IIS and IIS is case-insensitive).
-Joe - sstafford
Nimbostratus
Thanks, guys! - sstafford
Nimbostratus
Ok, so the client has come back to me, as clients are wont to do, and said. "This is great, but what I really need is for everything other than those four pages to be forced to http."
So, I came up with this rule, to be implented on the https virtual server.when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "*alumni/giving/gift/" - "*alumni/giving/pledge/" - "*alumni/directory/search.aspx" - "*alumni/directory/update.aspx" { don't do anything... } } default { HTTP::respond 301 Location "http://[getfield [HTTP::host] : 1][HTTP::uri]" } }
Any comments? - sstafford
Nimbostratus
Ah...Rejected by the server.
This works better...when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "*alumni/giving/gift/" - "*alumni/giving/pledge/" - "*alumni/directory/search.aspx" - "*alumni/directory/update.aspx" { don't do anything... } default { HTTP::respond 301 Location "http://[getfield [HTTP::host] : 1][HTTP::uri]" } } }
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
