Forum Discussion
mlamutt_62697
Oct 15, 2014Nimbostratus
Data group redirection or trim the hostname?
I am new to Irule scripting, and have a quick need for an Irule that redirects to a url based on the incoming uri that has an url (possibly encoded) as the first part of the URI. I was going to use a...
mlamutt_62697
Nimbostratus
Thanks for all your help. I made a few more changes, but it looks like it is working as needed. Feel free to critique if there are any areas of improvements.
when CLIENT_ACCEPTED {
Check the VS port to determine if connection is SSL or not
switch [TCP::local_port] {
"443" {
set proto "https"
}
default {
set proto "http"
}
}
log local0. "This is the new protocol - ${proto}"
}
when HTTP_REQUEST {
extract the string between the first and second slash,
assuming that this is always the hostname to redirect to.
Use a skip count of 1 to strip the first slash.
set firstFolder [findstr [string tolower [HTTP::path]] "/" 1 "/"]
log local0. "This is the domain - $firstFolder"
Remove the first folder from the uri unless it's listed in the class.
Using "string map" because it retains the case of the URI.
(important for Linux/Apache, and also to retain the case
of any query strings)
if { not [class match $firstFolder redirect.data.group] } {
set uri [string map -nocase {"/$hostname" ""} [HTTP::uri]]
log local0. "This is the new uri - $uri"
HTTP::respond 301 Location "${proto}:/$uri"
log local0. "This is the new url - ${proto}:/$uri"
}
}
Arie
Oct 17, 2014Altostratus
Looks good.
(If any of my replies answered your initial question, would you mind marking it as the answer? - Thanks!)
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