Here's what you may want to do, to be able to handle in the future many sub languages.
Check your host: if it begins with es
, then change your document root.
Here's the tip:
RewriteCond %{HTTP_HOST} ^es\.mydomain\.com$
# Change the path:
RewriteRule ^/?$ /public/www/index.php
And now something a little bit more advanced you may think about: multilanguage for the same website.
RewriteCond %{HTTP_HOST} ^(us|fr|pt)\.mydomain\.com$
# Create an environment variable to remember the language:
RewriteRule (.*) - [QSA,E=LANGUAGE:%1]
# Now check if the LANGUAGE is empty (= doesn't) exists
RewriteCond %{ENV:LANGUAGE} ^$
# If so, create the default language (=es):
RewriteRule (.*) - [QSA,E=LANGUAGE:es]
Ok now we have an environment variable where the language is set.
You asked for this:
es.domain.com
needs to point to /public/www/index.php
So add this final rule:
RewriteCond %{ENV:LANGUAGE} ^es$
# Change the root folder:
RewriteRule ^/?$ /public/www/index.php
So all in all:
RewriteCond %{HTTP_HOST} ^(us|fr|pt)\.mydomain\.com$
# Create an environment variable to remember the language:
RewriteRule (.*) - [QSA,E=LANGUAGE:%1]
# Now check if the LANGUAGE is empty (= doesn't exist)
RewriteCond %{ENV:LANGUAGE} ^$
# If so, create the default language (=es):
RewriteRule (.*) - [QSA,E=LANGUAGE:es]
# Change the root folder of the spanish language:
RewriteCond %{ENV:LANGUAGE} ^es$
# Change the root folder:
RewriteRule ^/?$ /public/www/index.php
What I don't get is: why can't you just write once for all languages, and make something like:
RewriteCond %{HTTP_HOST} ^(us|fr|pt)\.mydomain\.com$
# Create an environment variable to remember the language:
RewriteRule (.*) - [QSA,E=LANGUAGE:%1]
# Now check if the LANGUAGE is empty (= doesn't exist)
RewriteCond %{ENV:LANGUAGE} ^$
# If so, create the default language (=es):
RewriteRule (.*) - [QSA,E=LANGUAGE:es]
# WHATEVER THE LANGUAGE ADD IT TO THE URI:
RewriteRule (.*) $1?language=%{ENV:LANGUAGE} [QSA]
So now imagine someone types:
http://es.mydomain.com/
http://us.mydomain.com/
http://fr.mydomain.com/
http://pt.mydomain.com/
All point to the same piece of code and you just have to handle it in your Php
file: look into the $_GET['language']
variable and read the good "translation" file.
This is just an advice to help you making less work for a very robust application!
Hope this helps!
[Edit 1]
Here's the final stuff you may put into your .htaccess
file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(us|fr|pt)\.mydomain\.com$
RewriteRule (.*) - [QSA,E=LANGUAGE:%1]
RewriteCond %{ENV:LANGUAGE} ^$
RewriteRule (.*) - [QSA,E=LANGUAGE:es]
RewriteRule (.*) $1?language=%{ENV:LANGUAGE} [QSA]
</IfModule>
[Edit 2]
My latest rules do this:
Original URL
=> where it goes
http://pt.domain.com/ => http://pt.domain.com/?language=es
http://pt.domain.com/aa.php => http://pt.domain.com/aa.php?language=es
http://es.domain.com/ => http://es.domain.com/?language=es
http://es.domain.com/aa.php => http://es.domain.com/aa.php?language=es
http://domain.com/ => http://domain.com/?language=es
http://domain.com/bb.php => http://domain.com/bb.php?language=es
It doesn't change the path at all.
This one changes the path:
RewriteCond %{HTTP_HOST} ^(us|fr|pt)\.mydomain\.com$
RewriteRule (.*) - [QSA,E=LANGUAGE:%1]
RewriteCond %{ENV:LANGUAGE} ^$
RewriteRule (.*) - [QSA,E=LANGUAGE:es]
RewriteCond %{ENV:LANGUAGE} ^es$
RewriteRule ^/?$ /public/www/index.php
So this should give:
Original URL
=> where it goes
http://pt.domain.com/ => http://pt.domain.com/
http://pt.domain.com/aa.php => http://pt.domain.com/aa.php
http://es.domain.com/ => /public/www/index.php
http://es.domain.com/aa.php => http://es.domain.com/aa.php
http://domain.com/ => /public/www/index.php
http://domain.com/bb.php => http://domain.com/bb.php