'how to change WHMCS url by country
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.
Solution 1:[1]
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();
Solution 2:[2]
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]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | Faizan Khan |
