Reputation: 185
I have multiple domain names (FR,BE,NL,ES, ...), they are all redirected to the main webserver. The php-code is shared and is the same for all the domains & languages, I'm just identifying the active language with the param "lang=". I would like to identify which language to use trough an .htaccess file passing a lang param, as that param is the locale, I can also identify the domain country.
Ex.
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
Also I would like to get rid of the "www.".
Thanks for you help, LioH.
EDIT : Ok I still have a problem. I have this :
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]
When I try :
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.
I've read that RewriteCond is only applicable for the very next rule, do I need to put that RewriteCond before every rules ?
Upvotes: 1
Views: 236
Reputation: 785581
Place this code in your DOCUMENT_ROOT/.htaccess
file:
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]
Upvotes: 2