Forum Discussion
jpvrenen_46954
Nimbostratus
Mar 28, 2009Redirect using regular expressions
Hi all,
Just looking for some feedback on my iRule, it is working but would like to hear if it looks ok like this or if it can be written in a better/easier way using coding I am not aware of.
What I am trying to do is this:
redirect http://www.myserver.nl/find/some/*_Server1_*/Beer/now.html
to http://www.heineken.nl/want/Beer/now.html
Were http://www.heineken.nl/want is fixed just add Beer/now.html
&
redirect http://www.myserver.nl/find/some/*_Server2_*/Beer/now.html
to http://www.grolsch.nl/want/Beer/now.html
Were http://www.grolsch.nl/want is fixed just add Beer/now.html
So basically anything before and after _[Ss]erver[12]_ could be any character and also anything behind _[Ss]erver[12]_*/ could be anything.
To clarify we could have for example
http://www.myserver.nl/find/some/what_ever_Server1_now_what/Beer/or/Car/melike.html
then the outcome would be:
http://www.heineken.nl/want/Beer/or/Car/melike.html
I came up with the following iRule:
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/find/some/"}{
set uri [HTTP::uri]
log local0. "Original uri is => $uri"
switch -glob [HTTP::uri] {
"*_[Ss]erver1_*/*" {
regsub {/find/some/.*_[Ss]erver1_.[^/]*/} $uri "" uri
log local0. "Modified uri is => $uri"
HTTP::redirect "http://www.heineken.nl/want/$uri"
}
"*_[Ss]erver2_*/*" {
regsub {/find/some/.*_[Ss]erver2_.[^/]*/} $uri "" uri
log local0. "Modified uri is => $uri"
HTTP::redirect "http://www.grolsch.nl/want/$uri"
}
}
}
else {
pool NoBeer-80
}
}
Thanks for reading!
Jeroen
- hoolio
Cirrostratus
Hi Jeroen,
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