2

I am new in whmcs and I want to change the URL by country.

If a customer from the India has a URL like:- http://example.com/in/ or from the UK have a URL like http://example.com/uk/.

I am trying this .htaccess file but it is not working.

RewriteEngine on
RewriteRule ^in/(.*).php?(.*) /$1.php&country=india [NC,L,QSA] 

also I want to change the homepage according to country.

jhon
  • 188
  • 1
  • 15

2 Answers2

2

A better way would be to get the country from users IP address.

Using this PHP function found here:

// Get user IP
if (isset($_SERVER['HTTP_CLIENT_IP'])){
    $ip = $_SERVER['HTTP_CLIENT_IP'];
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
    $ip = $_SERVER['REMOTE_ADDR'];
}

$user_country_code = ip_info($ip, "Country Code"); // This will be a country code e.g 'IN', 'US'


// Redirect to Location
header('Location:' . "https://example.com/" . $user_country_code);
die();
Community
  • 1
  • 1
Ikhlak S.
  • 8,578
  • 10
  • 57
  • 77
0

if you are using Cloudflare no need to add an extra API just add this code under .htaccess

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP:CF-IPCountry} ^IN
RewriteCond %{REQUEST_URI} !(?:gif|png|jpg|jpeg|css)$ [NC]
RewriteRule !{REQUEST_URI}^ /?country=india [NC,NE,R,L]