Forum Discussion
iRule to redirect to home page if URI contains email address
Hey all,
We've gotten a request for an iRule on a system living on a legacy 10.x system (being decommed soon) that redirects to the home page if the URI contains an email address. If I were doing this in Apache, I'd do something like:
RewriteCond %{QUERY_STRING} "[_A-Za-z0-9-\+]+(.[_A-Za-z0-9-]+)(@|\%40)[A-Za-z0-9-]+(.[A-Za-z0-9]+)(.[A-Za-z]{2,})"
RewriteRule ^.*?.(html)$ / [F]
(Haven't tested that, just an example of where I'd start)
I see that regex's in iRules are frowned upon, but not sure how else to handle this. Any thoughts or examples would be appreciated.
3 Replies
- DevBabu
Cirrus
May be something like this. I have not tested it and used the regular expression that you have in question . If regular expression match redirect to some page. More on regexp can be found on.
https://devcentral.f5.com/articles/irules-101-10-regular-expressions
when HTTP_REQUEST { set uri [HTTP::uri] set result [regexp {[_A-Za-z0-9-\+]+(.[_A-Za-z0-9-]+)(@|\%40)[A-Za-z0-9-]+(.[A-Za-z0-9]+)(.[A-Za-z]{2,})} $uri] if($result) { HTTP::redirect "http://www.example.com/newlocation.html" } }
- JG
Cumulonimbus
Are you sure of your Apache rewrite rule? For it does not look like a redirect to me.
Also is an e-mail address the only thing expected in the query string?
It is better to illustrate your requirement with an example, for the sake of clarity.
- JG
Cumulonimbus
Here's an alternative one based on what I thought you wanted:
when HTTP_REQUEST { if { [HTTP::query] ne "" } { if { [regexp {\y[^@]+@[\w.-]+\.\w+\y} [HTTP::query]] } { HTTP::redirect "/" } } }
Recent Discussions
Related Content
* 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