Вопрос

Is it possible to set the DefaultLanguage in .htaccess according to an environmental variable or a rewrite condition?

Это было полезно?

Решение

You can use shell env variable in DefaultLanguage like this:

DefaultLanguage ${_LANG}

Where _LANG is the env variable set before Apache process has been started. I start my Apache as:

sudo bash -c 'export _LANG=de && /Applications/MAMP/bin/startApache.sh'

Другие советы

Suggestion of some alternatives based on en.example.com/aout

Using the command-line interface

Starting apache with

sudo bash -c 'export _LANG=en-US && /Applications/MAMP/bin/startApache.sh'

and in .htaccess

DefaultLanguage ${_LANG}

from previous answer by anubhava

Using FilesMatch in .htaccess

<FilesMatch "^en\.">
DefaultLanguage en-US
</FilesMatch>

<FilesMatch "^en-US\.">
DefaultLanguage en-US
</FilesMatch>

<FilesMatch "^es\.">
DefaultLanguage es
</FilesMatch>

from: http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html#FilesMatch_Directive

Using mod_rewrite in .htaccess

RewriteEngine On
RewriteBase /

#get language from host name
RewriteRule ^ - [E=LANG:en]
RewriteCond %{HTTP_HOST} ^(es|fr|en|se)\. [OR]
RewriteRule ^ - [E=LANG:%1]

Header always set Content-Language "%{LANG}e"
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top