apache url rewrite for multilanguage site

I'd like to achieve two goals using rewrite conditions under apache2 but this is not actually my cup of tea:

  • redirect mydomain.com to www.mydomain.com and this is pretty easy to do. I use:

    RewriteEngine On

    RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]

    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

  • redirect mydomain.es to www.mydomain.com/?lang=es (and so on for different languages)

How can I write the second statement? And how can I combine this rule with the first one?

Thank you in advance for your help!

Answers


Try :

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^mydomain\.[^.]+$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^mydomain\.([^.]+)/(.*) http://www.mydomain.com/?lang=$1 [L,R=301]

RewriteCond %{HTTP_HOST} !^www.mydomain.com$ [NC]
RewriteRule ^/(.*)$ http://www.mydomain.com/$1 [L,R=301]

It's Ok for mydomain.es, mydomain.fr, mydomain.pt but it's no OK for www.mydomain.es


Need Your Help

How do I plot observations each with multiple values in python?

python matplotlib plot

I have data for each individual participant from a survey. Each individual has a vector of data for example :

Using python for web databasing?

python

Is there a way to run a python script when loading an HTML page, to place variables on a page and set python variables based on <input>s? I already know python, and don't want to learn another