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
- sstafford
Nimbostratus
Ok, I've updated after more reading--also, I've switched to the "ends_with" operator. Will this work? - 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]" } } }
- 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."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]" } }
- sstafford
Nimbostratus
Ah...Rejected by the 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]" } } }
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