Forum Discussion
rodrigo_Benzaqu
Nimbostratus
Aug 02, 2007SSL redirection rule with regular expresion
Hi Guys,
I need to create a rule to redirect
/???/morethings to https://???/morethings
Do you think that is possible ?
Thanks
Rodrigo
5 Replies
- Sure you can do that. Make sure this iRule is on your HTTP virtual and not your HTTPS virtual or else you'll get into a circular loop.
when HTTP_REQUEST { switch -glob [HTTP::uri] { "/*/morethings" { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } } }
This will match the followinghttp://www.foo.com/onething/morethings
http://www.foo.com/onething/twothing/morethings
...
It will not match this:
Now, if you just want to make sure that your URI ends with "/morethings" you can do something simple like this:when HTTP_REQUEST { if { [HTTP::uri] ends_with "/morethings" } { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }
Hopefully this will get you going in the right direction.
-Joe - rodrigo_Benzaqu
Nimbostratus
Thanks Joe. But I want to redirect only if :
URI STARTS with /???/ where ? match 1 letter so if I have :
/abc/xxxxx --> match
/abcd/xxxx ---> doesn´t match
/pirulo --> doesn´t match - Just change the match pattern in the switch statement:
when HTTP_REQUEST { switch -glob [HTTP::uri] { "/abcd/*" - "/efgh/*" - "/ijkl/*" { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } } }
This will match only on the following
http://www.foo.com/efgh/*
http://www.foo.com/ijkl/*
It will not match onhttp://www.foo.com/aaaa/abcd/*
http://www.foo.com/abcd
http://www.foo.com/abc
http://www.foo.com/ab
That's because of the second slash in the match strings. Just modify the match statement using wildcards (*) for any sequence of characters/numbers/symbols/etc.
-Joe - rodrigo_Benzaqu
Nimbostratus
Joe, Sorry I think I´m not explaining my problem correct.
URI STARTS with /???/ where ? match 1 letter (Using regular expresions) so if I have for example :
/abc/xxxxx --> match so /[a-z][a-z][a-z]/
3 letters from a to z
/abcd/xxxx ---> doesn´t match
/pirulo --> doesn´t match - hoolio
Cirrostratus
I think Joe is suggesting using the switch command with strings instead of a regex because it's more resource intensive to use a regex.
You can use the question mark as a wildcard representing any single character. So this should match what you've described so far, where any request that starts with /, any three characters, another forward slash followed by anything would be redirected to the same host and URI via HTTPS:when HTTP_REQUEST { switch -glob [HTTP::uri] { /???/* { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } } }
You can check the TCL man page on switch (Click here) and string match (Click here) for details on string wildcards.
Aaron
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
