Page 1 of 1

How to modify Env Variable? + optimization

New postPosted: 19 Oct 2009 17:33
by salami84
Hi,

I'm new to the Env vars as I just discovered this while searching for some solutions for my website. My website is going to be on 2 (cloud) servers. 1 in the US and 1 in the UK. They are exactly the same. Now I'm using htaccess to redirect visitors to correct version (based on ip-country) to serve them with fastest website.
Now to select the server I have in my .htaccess:
Code: Select all
#server select
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^(UK|NL|BE|FR|DE|ES|AT|CH|PT|IE|AD|MC|DK|IT|NO|SE|PL|CZ|SI|HU|HR|UA|RO|EE|LV|LT|RU|GR|BG|TR|IQ|IR|SA|EG|DZ|MA|TN|NE|FI|IS|PK|AF|IN)$
RewriteCond %{HTTP_HOST} !^(www\.)?mywebsite\.eu [nc] #prevent looping
RewriteRule ^(.*)$ http://www.mywebsite.eu$1 [NC]

RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} !^(UK|NL|BE|FR|DE|ES|AT|CH|PT|IE|AD|MC|DK|IT|NO|SE|PL|CZ|SI|HU|HR|UA|RO|EE|LV|LT|RU|GR|BG|TR|IQ|IR|SA|EG|DZ|MA|TN|NE|FI|IS|PK|AF|IN)$
RewriteCond %{HTTP_HOST} !^(www\.)?mywebsite\.com [nc] #prevent looping
RewriteRule ^(.*)$ http://www.mywebsite.com$1 [NC]


This would mean every page requested on any of the servers creates a lookup, which is kinda redundant. Does anybody have any tips on how do to this 'server select' only once per session for example?

2nd question is as following:
I have some redirects to get to the right language version I have 3 languages at the moment and they are all 3 available on both servers (I mean there are people speaking Spanish in US as well as in EU). So I'm using subdomains for the language version and for this I do some redirection might a customer go there using wrong url
Code: Select all
RewriteRule ^en/(.*)$ http://%{HTTP_HOST}/$1 [R=301,L] 
RewriteRule ^nl$ http://nl.%{HTTP_HOST}/ [R=301,L]
RewriteRule ^es$ http://es.%{HTTP_HOST}/ [R=301,L]
RewriteRule ^nl/(.*)$ http://nl.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^es/(.*)$ http://es.%{HTTP_HOST}/$1 [R=301,L] 


The problem is above code will NOT work as HTTP_HOST will include the 'www' part and http://es.www.domain.com is not gonna work of course. So I actually need to make a Env var which strips the 'www' part out of HTTP_HOST but I have no clue on how to do this. I've seen how to set your own variable in .htaccess but the stripping part is the problem.

Thank you very much for your advise.

Best regards,