0

I must create a multi-language website. In order to achieve this aim, I want to point subdomain representing a language to the 1rst URL parameter (GET variable) of the domain in my virtualhost or htaccess configuration.

The scheme is the follow :

example.com => / 

([a-z-]+).example.com => /?lang=$1

([a-z-]+).example.com/directory1/ => /directory1/?lang=$1

([a-z-]+).example.com/directory1/page.html => /directory1/page.html?lang=$1

etc... whatever the number of directories and pages.

So, according to this scheme :

en-en.example.com matches /?lang=en-en

en-en.example.com/directory1/ matches /directory1/?lang=en-en

en-en.example.com/directory1/page.html matches /directory1/page.html?lang=en-en

etc... whatever the number of directories and pages.

So how can I do that in my apache configuration?

Mr. Raspberry
  • 3,918
  • 13
  • 32
totoaussi
  • 123
  • 5

1 Answers1

0

I think something like this in your .htaccess or virtual host config file will do the trick; This matches only two-letter subdomain names - adjust the first regex accordingly... e.g. ([a-z-]+)

RewriteEngine On
RewriteCond %{HTTP_HOST} "^([a-z]{2})\.example\.com$"
RewriteRule "^(.*)$" http://example.com$1?lang=%1
TH_
  • 1
  • 1
  • Hello, It works, but I forgot to say that the url with get parameter (lang?=en) must be transparent. That is say : If you type in the browser url bar en.example.com, the url remains en.example.com but in the background the right url is example.com/?lang=en. Because in your solution, en.example.com redirects to example.com?lang=en, so it's not transparent. It is possible to do that ? – totoaussi Oct 01 '15 at 09:55