Forum Discussion
DM_5174
Nimbostratus
Nov 07, 2007Case-sensitive URL Redirection
Hello all,
I have created a 4x iRule that will redirect based on specific
words after the FQDN "http://%h/". So if i put "http://www.primarysite.com",
i get redirected to the main page, however if you enter "home" or "HOME" (lower case or upper case), it redirects you to the secondary site.
The quesion here is: Can I use RegEX, for example /[H][h][O][o][M][m][E][e]
in the code so to consolidate so i don't have to use two "if" statements?
By doing this, the user can put any of the combo upper or lower and still
get the same result, which is a redirection to "http://www.secondarysite.com/secure".
if (http_host == "www.primarysite.com" and http_uri == "/home") {
redirect to "www.secondarysite.com/secure/"
}
else {
if (http_host == "www.primarysite.com" and http_uri == "/HOME") {
redirect to "www.secondarysite.com/secure/"
}
else {
use pool APACHE_WEB_SERVERS
}
}
Thank you!
4 Replies
- hoolio
Cirrostratus
Hello,
If you're running 4.6.x, you can use the tolower function to set the URI to lowercase before doing the string comparison. Else, in previous versions, you can use matches_regex.
tolower:
if ((tolower(http_host)) == "www.primarysite.com" and (tolower(http_uri) == "/home")){
matches_regex:
if (http_host matches_regex "(?i:www.primarysite.com)" and http_uri matches_regex "(?i:/home)"){
The ?i: portion of the regex enables a case-insensitive comparison and doesn't capture the matching string into a backreference.
I haven't tested the i flag, but it's a standard regex option so I expect it would work. If not, you could use the [hH][oO][mM][eE] approach.
Aaron - DM_5174
Nimbostratus
I have tried the "i" switch and it does not work for the irule version i am running. I have tried the other approach and came up with a 404 error. I think the syntax is incorrect...Can you let me know if this is correct?
Thanks again!if (http_host == "www.primarysite.com" and http_uri == "/[hH][oO][mM][eE]") { redirect to "www.secondarysite.com/secure/" } else { use pool APACHE_WEB_SERVERS } - hoolio
Cirrostratus
I assume you're getting a 404 because the request is for /home and that doesn't exist on the web servers in the apache pool.
Instead of ==, try using matches_regex. Also, you should specify the protocol in the redirect.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 }
Aaron - DM_5174
Nimbostratus
Awesome! that worked!
Thanks for the help Aaron!
-Anhtuan
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
