Forum Discussion
cin_75063
Nimbostratus
Sep 16, 2009Redirecting HTTP to HTTPS except certain URLs
Hi
I want to redirect all HTTP request to HTTPS except certain URIs("/abc/0001, /abc/0002, .... /abc/000n").
I'm very new to iRule, so I'd appreciate it if someone could review my script.
////////////////////////////////////////////////////////////////
class redirect_group {
"abc"
}
when HTTP_REQUEST {
set uri [findstr [HTTP::uri] "" 1 "/"]
if {not([matchclass $::redirect_group equals $uri])} {
redirect to "https://[HTTP::host][HTTP::uri]"
}
}
////////////////////////////////////////////////////////////////
Thank you in advance.
- hoolio
Cirrostratus
Hello, - cin_75063
Nimbostratus
Thank you, AaronAlso, in 9.x/10.x you can use HTTP::redirect instead of "redirect to".
- hoolio
Cirrostratus
Is /abc/ static (ie, always the same)? Or are there multiple values for the first directory that you don't want to redirect for? - cin_75063
Nimbostratus
Hello, Aron - hoolio
Cirrostratus
That makes sense. If you define the datagroup as /abc/, /xyz/, then you can make the iRule simpler:when HTTP_REQUEST { if {not [matchclass [HTTP::uri] starts_with $::redirect_group]}{ Redirect to https HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }
- cin_75063
Nimbostratus
Thank you, Aaron - hoolio
Cirrostratus
Good. Let me know if you see any issues.
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