.htaccess is not my strong suit and I've found bits and pieces of what I need to know in various posts but not the whole shebang, any guidance welcome.
What I have:
- A website for U.S. visitors with a subdomain for Canadian visitors.
- Both are on a CDN which obfuscates the ip occasionally, it's a proxy thing, causing my non htaccess based geotargeting to fail.
- The CDN does provide a country code in referrer data, $_SERVER['HTTP_CF_IPCOUNTRY'] AA, with AA representing the visitors country. Canada is CA, U.S. is US, of course.
What I need:
- If a visitor to the US site is CA based he is redirected to the CA subdomain - [
ca.example.com...]
- If a visitor the the US site is based in the US or in another country besides CA nothing happens, they stay on http://www.example.com.
- the redirect to send the visitor to the SAME url, only changing the www to ca and vice versa, the sites share the same url structure.
What I know:
- I need to add the code the .htaccess files in both the main site root and the subdomain root.
- I need to set the condition to check the country code and redirect if necessary.
- I don't want to block anyone, just to check if a redirect is in order.
- I need the code not to cause problems if a file is served by my server instead of the CDN, in which case there will be no $_SERVER['HTTP_CF_IPCOUNTRY'] set.
I'd post my best effort, but there have been two dozen or so attempts that don't work fully and I'm a little lost at this point... advice?