Forum Moderators: phranque
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ [url.ca...] [L]
The problem is that url.ca is just a folder called "ca" in url.com, so I get a loop. If I redirect to any other external domain it works fine.
To solve this I placed a blank .htaccess in the "ca" folder. Apache didn't seem to recognise it so I placed an .htaccess with the following:
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
And it worked. I came in today, and it no longer works.
Any ideas?
To prevent a loop, add code to stop the redirect to www.url.ca if you already are in www.url.ca:
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteCond %{HTTP_HOST} !^www\.url\.ca$
RewriteRule .* http://www.url.ca/ [R=301,L]
Another note: In order to work, you must use the 301 external redirect as shown. If this is not acceptable (because you want to hide the redirect), you'll need to implement a cookie or a session-tracking variable to keep track of each visitor's current country-domain.
Jim
I've got some other things I need to get done, and I'll be off-line for awhile, so here's a "just-in-case". Assuming that you meant to say www.url.com/ca, rather than www.url.ca, you can use this.
To prevent a loop, add code to stop the redirect to www.url.com/ca if you are already in www.url.com/ca:
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteCond %{REQUEST_URI} !^/ca
RewriteRule ^(.*)$ /ca/$1 [L]
If you really want to redirect only to the /ca home page, use:
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteCond %{REQUEST_URI} !^/ca
RewriteRule .* /ca/ [L]
HTH,
Jim
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteCond %{HTTP_HOST}!^www\.url\.ca$
RewriteRule .* [url.ca...] [R=301,L]
Cheers,
Hayden