Redirect users according to their geo location

I want to create a rule where if a user is from India he will be redirected to /en-in otherwise no redirection. How to do that, i want to avoid php so is there any other idea ??

Also avoid Javascript? if yes you cannot.

can htaccess work ?

No, you must use javascript or php at least.

<script language="Javascript" src="http://gd.geobytes.com/gd?after=-1&variables=GeobytesLocationCode,GeobytesCode,GeobytesInternet"></script>
<script language="Javascript">
if(typeof(sGeobytesLocationCode)=="undefined"
   ||typeof(sGeobytesCode)=="undefined"
   ||typeof(sGeobytesInternet)=="undefined")
{
   // Something has gone wrong with the variables, so set them to some default value,
   // maybe set a error flag to check for later on.
   var sGeobytesLocationCode="unknown";
   var sGeobytesCode="unknown";
   var sGeobytesInternet="unknown";
}
if(sGeobytesLocationCode=="GRATATHE")
{
   // Visitors from India would go here
   window.open("enter Indian URL here");
}else if(sGeobytesCode=="IN")

</script>

just adding this will work ??

there is one way to make it work using .htaccess only if you are using cloudflare.
First from network tab in cloudflare enable IP Geolocation
Then add this code in your site .htaccess

SetEnvIf CF-IPCountry “(.*)$” Country=$1
RewriteCond %{ENV:Country} IN
RewriteRule ^(.*)$ https://yoursite.com/en-in$1 [R,L]

Reference: https://community.cloudflare.com/t/redirecting-specific-country-to-sub-domain/12688/7?u=aqibhussain2001

2 Likes

I want to redirect indian visitors from example.com/plans to example.com/inplans
Example.com will be same for everyone. Where should i include in htacess ??

Best would be making sub domains and using the Javascript method given by @anon19508339

Yeah using cloudflare.

SetEnvIf CF-IPCountry “(.*)$” Country=$1
RewriteCond %{ENV:Country} IN
RewriteRule ^plans/(.*)$ /inplans [R,L]

Replace plans with one you want to redirect from and replace inplans with where you want to redirect to.

Reference: Redirect One Directory To Another With .htaccess | #! code

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.