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...
Arie
Oct 17, 2014Altostratus
Ah - I didn't notice that my update hadn't been saved (looks like the forum is having problems). For other members, here's the correct code:
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 "/"]
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 equals class_exceptionList] } {
set uri [string map -nocase {"/$hostname" ""} [HTTP::uri]]
HTTP::respond 301 Location "http://$firstFolder$uri"
}
}
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