Forum Discussion
Can we perform URL rewrite based on the header in the request using iRule or any other way?
For Example suppose a request www.abc.com with a header wherein language is German is received, can we rewrite the URL such that it becomes www.abc.com/ge and serves a German web page instead of the default English page...
1 Reply
- Kevin_Stewart
Employee
Absolutely. Something like this:
when HTTP_REQUEST { switch [HTTP::header Accept-Language] { "en" { HTTP::uri "/en[HTTP::uri]" } "ge" { HTTP::uri "/ge[HTTP::uri]" } } }This will look at the incoming Accept-Language header and insert the respective language path before the original request. So a request to www.abc.com/foo/bar with an Accept-Language value of "ge" will produce a request to the server as www.abc.com/ge/foo/bar.
Now the above should work as long as the server doesn't return relative links to its resources under this path. Example:
/en/image.jpgIf it does do this, then you'll need a minor modification of the above rule to catch this and disregard URI modification if the language path already exists:
when HTTP_REQUEST { switch [HTTP::header Accept-Language] { "en" { if { not ( [HTTP::uri] starts_with "/en/" ) } { HTTP::uri "/en[HTTP::uri]" } } "ge" { if { not ( [HTTP::uri] starts_with "/ge/" ) } { HTTP::uri "/ge[HTTP::uri]" } } } }The HTTP::uri command will modify the URI as it passes through the proxy, and will be transparent to the user (won't show up in the address bar).
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