17

I have two different domains (let's say www.site1.com and www.site2.com) that point to the same hosting server.

I need the two different domain names because I want to use the first one for the italian contents and the second one for the english contents. The contents are the same, unless for the language, but the domains have to be different.

So, I'd like to write a rule that lets me translate from:

  • www.site1.com to /?lang=it

  • www.site2.com to /?lang=en

I usually use the same domain name for many different languages rewriting from www.site.com/it/ to /?lang=it (of course, a transparent rewriting - the user doesn't see any different URL).

I'd like to achieve the same using different domains but I can't figure out how... I've been working on it for hours and I can't achieve what I want!

Usually I use this:

RewriteCond %{REQUEST_URI} /([a-z]{2})
RewriteRule ^([a-z]{2})[/]*$ /index.php?lang=$1 [NC,QSA]

I can't get this one work, to use different domains:

RewriteCond %{HTTP_HOST} ^www.site1\.com [NC]
RewriteCond %{REQUEST_URI} !^/index.php?lang=it
RewriteRule ^(.*)$ /index.php?lang=it [NC,QSA]

RewriteCond %{HTTP_HOST} ^www.site2\.com [NC]
RewriteCond %{REQUEST_URI} !^/index.php?lang=en
RewriteRule ^(.*)$ /index.php?lang=en [NC,QSA]
4

1 回答 1

34

Lawrence Cherone - Thank you, that one works like a charm! Now it works:

RewriteCond %{HTTP_HOST} ^www\.site1\.com [NC] 
RewriteRule ^(.*)$ index.php?lang=it [NC,QSA] 
RewriteCond %{HTTP_HOST} ^www\.site2\.com [NC] 
RewriteRule ^(.*)$ index.php?lang=en [NC,QSA] 

Of course I check the www redirect before this rule.

Thank you!!

于 2012-04-20T07:09:15.917 回答