Forum Discussion
Diacritics in iRules
I have URIs with accented characters for some international sites. I can forward a URI with diacritics by URL encoding the destination address.
But I don't seem to be able to match an encoded or decoded URL that originally contained accented characters in a switch statement, no matter what I try.
Forwarding to an encoded URL works:
when HTTP_REQUEST {
switch [string tolower [HTTP::uri]] {
/testme {
HTTP::respond 301 Location "http://mydomain.com/restauraci%C3%B3n"
}
}
Matching an encoded URI in a switch statement doesn't:
when HTTP_REQUEST {
switch [string tolower [HTTP::uri]] {
/restauraci%C3%B3n {
HTTP::respond 301 Location "http://mydomain.com/newlocation"
}
}
Browsing to http://mydomain.com/restauración (http://mydomain.com/restauraci%C3%B3n) doesn't get forwarded.
I did a test to see what the decoded URI looks like:
when HTTP_REQUEST {
switch [URI::decode [string tolower [HTTP::uri]]] {
/restauraci* {
200 content "[URI::decode [HTTP::uri]]"
}
}
Browsing to http://mydomain.com/restauración I get "/restauración"
Using the same rule without the decode, I get "/restauraci%C3%B3n"
Trying to match the decoded URI (or anything else) doesn't work either:
when HTTP_REQUEST {
switch [URI::decode [string tolower [HTTP::uri]]] {
/restauración -
/restauraci%C3%B3n -
/restauración {
HTTP::respond 301 Location "http://mydomain.com/newlocation"
}
}
Is there a simple way to filter on an encoded URI?
- hooleylistCirrostratusIf the URI is encoded properly by the browser, this should work as long as you set the cases to lower case:
when HTTP_REQUEST { switch [string tolower [HTTP::uri]] { /restauraci%c3%b3n { HTTP::respond 301 Location "http://mydomain.com/newlocation" } }
- mdcarson_58978NimbostratusI skipped the string tolower in my simplified examples, but we actually have it in the iRule.
- hooleylistCirrostratusCan you log the value from the browser?
when HTTP_REQUEST { switch [string tolower [HTTP::uri]] { /restauraci%c3%b3n { log local0. "matched: /restauraci%c3%b3n" HTTP::respond 301 Location "http://mydomain.com/newlocation" } default { log local0. "no match: [string tolower [HTTP::uri]]" } }
Recent Discussions
Related Content
* 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