Forum Discussion
DM_5174
Nimbostratus
Nov 09, 2007case-sensitive URL redirection - Code conversion
Hi all,
I have created the iRule below with the help of users on this forum in version 4.x, however we also have LBs with version 9.x. Please help me in converting this to version 9.x?
Basically when a someone connects using the URL "http://www.primarysite.com" they get routed to the main page, however, when they enter "home" after the FQDN, they need to get routed to "https://www.secondarysite.com/secure". The "home" needs to be case-insensitive, where it does not matter if they enter it in upper or lower case letters or even a combo, i.e. "hOmE", the result should be that they get routed to "https://www.secondarysite.com/secure/".
if (http_host == "www.primarysite.com" and http_uri matches_regex "/[hH][oO][mM][eE]")
{
redirect to "https://www.secondarysite.com/secure/"
}
else {
use pool APACHE_WEB_SERVERS
}Thanks all!
1 Reply
- In 9.x iRules, string case is a lot easier to manage with the help of the TCL string command.
This should work for you.when HTTP_REQUEST { if { ([HTTP::host] equals "www.primarysite.com") && ([string tolower [HTTP::uri]] equals "/home") } { HTTP::redirect "https://www.secondarysite/secure/" } else { pool APACHE_WEB_SERVERS } }
Or, better yet, if you have APACHE_WEB_SERVERS as the default pool within the Virtual Server, you can omit the else clause:when HTTP_REQUEST { if { ([HTTP::host] equals "www.primarysite.com") && ([string tolower [HTTP::uri]] equals "/home") } { HTTP::redirect "https://www.secondarysite/secure/" } }
Keep in mind that you can also use the "starts_with" operator in the HTTP::uri comarison if you want to match all URIs that, well, start with "/home" (ie, /home/one, /home/two, ...)
Let me know if this doesn't work for you...
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
