0

I am trying to serve accept-language header-dependent static files, while the URL should always look the same.

The important snippet of the apache 2.4.10 config:

... RewriteEngine On RewriteCond %{HTTP:Accept-Language} ^de [NC] RewriteRule ^/$ http://$mydomain.tld/index-de.html [P,L] RequestHeader set accept-language "en" Header always set accept-language "en" RewriteRule ^/index-en.html / [R] RewriteCond %{HTTP:accept-language} ^en [NC] RewriteRule ^/$ http://$mydomain.tld/index-en_trick.html [P,L] ...

While a request at the domain-level works fine (e.g. serving "de" : curl -Lvvv --header "accept-language: de" http://$mydomain.tld), the following doesn't work (desired outcome is to get the english version, even if the accept-language of the initial request is de):

$ curl -Lvvv --header "accept-language: de" http://$mydomain.tld/index-en.html * Trying ... * Connected to ... port 80 (#0) > GET /index-en.html HTTP/1.1 > Host: $mydomain.tld > User-Agent: curl/7.47.0 > Accept: / > accept-language: de > < HTTP/1.1 302 Found < Date: Thu, 03 Jan 2019 16:16:35 GMT < Server: Apache/2.4.10 (Linux/SUSE) < accept-language: en < Location: http://$mydomain.tld/ < Content-Length: 280 < Content-Type: text/html; charset=iso-8859-1 < * Ignoring the response-body * Connection #0 to host $mydomain.tld left intact * Issue another request to this URL: 'http://$mydomain.tld/' * Found bundle for host $mydomain.tld: 0x55a6899200c0 [can pipeline] * Re-using existing connection! (#0) with host $mydomain.tld * Connected to $mydomain.tld (...) port 80 (#0) > GET / HTTP/1.1 > Host: $mydomain.tld > User-Agent: curl/7.47.0 > Accept: / > accept-language: de > < HTTP/1.1 200 OK < Date: Thu, 03 Jan 2019 16:16:35 GMT < Server: Apache/2.4.10 (Linux/SUSE) < accept-language: en < accept-language: en < Last-Modified: Thu, 27 Dec 2018 16:34:07 GMT < ETag: "140d-57e0383f21500" < Accept-Ranges: bytes < Content-Length: 5133 < Vary: Accept-Encoding < Content-Type: text/html; charset=utf-8

Always I am getting the german version. So, if the domain-level lookup with a language-header works, it should be possible to rewrite any URL to that domain-level and pass a desired, rewrited language-header, so that that also works. I searched a lot around, tried a lot, but I somehow seem to miss something - or is it just not possible? I mean, I know, it contradicts the origin's language-header. But it would be nice to have language-dependent links while at the same time serving (and exposing) a canonical URL without forcing the user to tinker with her browser's language-header.

So, maybe the answer of @alien-life-form to this related post is true - you cannot rewrite Client headers at all?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.