多个域名扩展,一个服务器,一个代码,一个htaccess


Multiple domain extension, one server, one code, one htaccess

我有多个域名(FR,BE,NL,ES,…),它们都被重定向到主web服务器。php代码是共享的,所有的域名&语言,我只是用参数"lang="来标识活动语言。我想通过传递语言参数的.htaccess文件确定使用哪种语言,因为该参数是区域设置,所以我还可以确定域的国家。

if mydomain.nl & page is /contact    -> /code/contact.php?lang=nl_NL
if mydomain.fr & page is /contact    -> /code/contact.php?lang=fr_FR
if mydomain.es & page is /contact    -> /code/contact.php?lang=es_ES
if mydomain.be & page is /fr/contact -> /code/contact.php?lang=fr_BE
if mydomain.be & page is /nl/contact -> /code/contact.php?lang=nl_BE 
if mydomain.be & page is /en/contact -> /code/contact.php?lang=en_BE 

我还想去掉www.

谢谢你的帮助,LioH .

编辑:好吧,我还有个问题。我有这个:

RewriteCond %{HTTP_HOST} '.be$ [NC]
RewriteRule  ^fr/a-propos$  /code/internal.php?lang=fr_BE&id=7 [QSA,L]
RewriteRule  ^fr/pourquoi$ /code/internal.php?lang=fr_BE&id=11 [QSA,L]
RewriteRule  ^fr/logout$ /scripts/logout.php?lang=fr_BE [QSA,L]
RewriteCond %{HTTP_HOST} '.fr$ [NC] 
RewriteRule  ^a-propos$ /code/internal.php?lang=fr_FR&id=7  [QSA,L]
RewriteRule  ^pourquoi$ /code/internal.php?lang=fr_FR&id=11 [QSA,L]
RewriteRule  ^logout$ /scripts/logout.php?lang=fr_FR [QSA,L]

当我尝试:

Mydomain.be/fr/logout -> It works 
Mydomain.fr/logout -> It works 
Mydomain.fr/fr/logout -> It works also but it shouldn't and will be ugly for duplicate content.

我读到RewriteCond只适用于下一个规则,我需要把RewriteCond在每个规则之前吗?

将此代码放入您的DOCUMENT_ROOT/.htaccess文件:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{HTTP_HOST} '.nl$ [NC]
RewriteRule ^([^/.]+)/?$ /code/$1.php?lang=nl_NL [L,QSA]
RewriteCond %{HTTP_HOST} '.fr$ [NC]
RewriteRule ^([^/.]+)/?$ /code/$1.php?lang=fr_FR [L,QSA]
RewriteCond %{HTTP_HOST} '.es$ [NC]
RewriteRule ^([^/.]+)/?$ /code/$1.php?lang=es_ES [L,QSA]
RewriteCond %{HTTP_HOST} '.be$ [NC]
RewriteRule ^([a-z]{2})/([^/.]+)/?$ /code/$2.php?lang=$1_BE [L,QSA]
相关文章: