Forum Discussion
Puli
Mar 31, 2011Nimbostratus
iRule to detect browser language and re-direct
Am working an iRule to detect browser's language and re-direct to the appropriate help page.
For example
www.abc.com browser language is french send it to www.abc.com/fr/help
Can you provide me with sample code how i can achieve this.
Can you recommend any tool to test it? to change my browser language for testing purposes ?
thanks, appreciate it.
Puli.
- The_BhattmanNimbostratusHi Puli,
when HTTP_REQUEST { if { [HTTP::header "Accepted-Language"] contains "fr" } { HTTP::redirect http://www.abc.com/fr/help } }
when HTTP_REQUEST { switch -glob [HTTP::header "Accepted-Language"] { "*fr*" - { HTTP::redirect http://www.abc.com/fr/help } "*en-us*" - { HTTP::redirect http://www.abc.com/fr/help } default - { HTTP::redirect http://www.abc.com/help } } }
- Colin_Walker_12Historic F5 AccountKeep in mind both of those examples are using a "contains" style match, which means you're not necessarily using their preferred language, just one that they support. To be more specific you'd want to find the first language in the list.
- hooleylistCirrostratusYou'd probably also want to only check a few URIs (/ and the main index page come to mind) so you're not checking the header on every request. Also, if the help pages are on the same VS as this iRule, you'd need some kind of logic to avoid a loop of redirects.
foreach line [split [HTTP::header Accept-Language] "," ] { switch -glob [getfield $line ";" 1] { "de*" { ... Break out of the loop as we found a match break } }
- Colin_Walker_12Historic F5 Account@Aaron - Agreed on the loop being expensive. It's likely an unnecessary cost, too. You could easily get the first entry or two without having to loop through the entire header. You'd save cycles and lose effectively no functionality that way.
- PuliNimbostratusI agree Aaron, just looking at the first language entry and switch will be less expensive.
- PuliNimbostratusFound this useful add-on on firefox to switch you browser locales to different languages.
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