How to redirect to a specific folder by country?

shanew

Active member
Hello,

In my root domain, example.com, i installed Xenforo but I also have a blog, and it is installed at example.com/blog/ now i want visitors from Canada when they visit my domain (Xenforo), the domain will redirect to example.com/blog/ while US visitors will view example.com

I mean this
CA visitors visit example.com --> will be redirected to example.com/blog/
US visitors visit example.com --> will be redirected to example.com

How can I do that? what is the best way?
 
One problem you will run into is if people are using a proxy or TOR. Those will not necessarily report coming out of Canada or the US.
You also don't specify what HTTP server you are using (NGINX, Apache, LiteSpeed, OpenLiteSpeed). Each of those would be slightly different for the solution.

If Apache, see if this link will help you.
 
One problem you will run into is if people are using a proxy or TOR. Those will not necessarily report coming out of Canada or the US.
You also don't specify what HTTP server you are using (NGINX, Apache, LiteSpeed, OpenLiteSpeed). Each of those would be slightly different for the solution.

If Apache, see if this link will help you.
Thank you for useful link, in the case, I want to use htaccess with server config without using PHP codes then it is possible?
I want to have a simpler way :)
 
Thank you for useful link, in the case, I want to use htaccess with server config without using PHP codes then it is possible?
I want to have a simpler way :)
Yes, that link gives you several options to use, PHP, htaccess, PERL, ASP, ASP.NET, RUBY.

For htaccess it gives this
Code:
RewriteEngine On
 
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^CA$
RewriteRule ^(.*)$ http://example.com/blog/ [L]
 
RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^US$
RewriteRule ^(.*)$ http://example.com [L]
 
Top Bottom