# Almost all of this is thanks to Pascal Fellerich: # http://www.fellerich.lu/articles/multiviews # Enable Multiviews option for multiple language support Options +MultiViews Options +FollowSymLinks RewriteEngine On RewriteBase / # DirectoryIndex: MultiViews also looks for .png and .gif, this enables # a language dependent display of images. E.g. flag => flag.lb.png #DirectoryIndex index index.php index.html index.htm index.png index.gif DirectoryIndex index.html # add languages, don't trust the apache base config! AddLanguage de .de AddLanguage en .en AddCharset utf-8 .de AddCharset utf-8 .en # Default .html is in this language: DefaultLanguage en # some defaults.... LanguagePriority en de ForceLanguagePriority Fallback # Detect IE first -- and Chrome/Chromium BrowserMatch MSIE is_msie=1 BrowserMatchNoCase chrome is_msie=1 # Cache Control: 60 minutes for static content Header set Cache-Control "max-age=3600, public" # add must-revalidate for dynamic content (even html becomes dynamic due to MultiViews!) Header set Cache-Control "max-age=0, private, must-revalidate" # conditional headers for IE. Guess why. Header set Cache-Control "no-cache, no-store" env=is_msie Header set Pragma "no-cache" env=MSIE Header set Expires "-1" env=MSIE # 1. if there is only a lang code on the query string, make this the new # virtual base language directory and redirect accordingly. # Search robot safe! RewriteCond %{QUERY_STRING} ^(de|en)$ RewriteRule ^((de|en)/)?(.*?)(\.(de|en))*$ %1/$3? [E=LANG:%1,R=302,L] # 2. If a language cookie is set, don't bother with the virtual subdir # and redirect to the main representation, and use the cookie setting RewriteCond %{HTTP_COOKIE} "lang=(.+)" RewriteRule ^(de|en)/(.*) $2 [R=302,L] # 3. make virtual language subdirectories and set a temp ENV var RewriteRule ^(de|en)/(.*) $2 [E=LANG:$1] # mod_rewrite prepends REDIRECT_ to each set Env Var SetEnvIf REDIRECT_LANG de prefer-language=de Header append Vary cookie SetEnvIf REDIRECT_LANG en prefer-language=en Header append Vary cookie # Language selection override via cookie (cookie set by JS or similar) SetEnvIf Cookie "lang=(.+)" prefer-language=$1 Header append Vary cookie Options +Indexes ForceType application/octet-stream Header set Content-Disposition attachment