Mobile app version of vmapp.org
Login or Join
Radia820

: Serve index.html by language and charset (a thing from the past) In a digital archaeology project I have found a web server directory with files dated from 2001 that had a peculiar collection

@Radia820

Posted in: #Apache #Internationalization #Language

In a digital archaeology project I have found a web server directory with files dated from 2001 that had a peculiar collection of index.html files with names ending with two letter codes of different languages and language charsets, i.e.

index.html.ca index.html.ja.jis index.html.ru.iso-ru
index.html.cz index.html.kr.iso-kr index.html.ru.koi8-r
index.html.de index.html.lb.utf8 index.html.ru.ucs2
index.html.dk index.html.nl index.html.ru.ucs4
index.html.ee index.html.nn index.html.ru.utf8
...


How do I configure modern Apache to serve different static pages based on the value of Accept-Language header?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Radia820

2 Comments

Sorted by latest first Latest Oldest Best

 

@Carla537

Those files are almost certainly meant to be served via Apache content negotiation. Since there does not appear to be a .var file to serve as an explicit type map, and since the file name extensions correspond to standard language and charset codes, they're probably meant to be used with the implicit MultiViews mechanism.

To enable MultiViews for the directory containing these files, add the following directive into an .htaccess file in that directory (or into a matching <Directory> section in the global Apache config):

Options +MultiViews


This will make Apache automatically resolve requests for nonexistent files by appending additional extensions based on the language, MIME type and charset preferences indicated by the HTTP Accept, Accept-Charset and Accept-Language headers. For example, a request for index.html might cause Apache to instead return the contents of index.html.de or index.html.ja.jis or index.html.ru.utf8, depending on the preferred language(s) configured in the user's browser.

Note that, in addition to content negotiation, you should also provide some way for users to explicitly select the version of the page that they prefer. When using MultiViews, this can be as simple as providing direct links to the translated pages with the language code included.

10% popularity Vote Up Vote Down


 

@Megan663

I would recommend issuing redirects so that search engines can view unique urls for each language. Here are some rewrite rules that you could use in your .htaccess file:

RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^index.html$ /index.html.de [L,R=302]
RewriteCond %{HTTP:Accept-Language} ^ru [NC]
RewriteRule ^index.html$ /index.html.ru.utf8 [L,R=302]
...



NC is "no case" (case insensitive)
L is "last" (stop processing other rules)
R=302 is a temporary redirect


You would still need a default index.html for browsers that don't send the header with a recognized value.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme