Author Topic: Intesting plugin  (Read 154 times)

orisa

  • Newbie
  • *
  • Posts: 2
    • View Profile
Intesting plugin
« on: March 21, 2018, 10:05:22 AM »
The idea of this plugin is a must have, perhaps it needs still a little re-work, if I come from UK using uk.mydomain.com it still tell me to redirect me to uk.mydomain.com over and over.

the main concept is
  • If I come from Canada and I enter www.mydomain.com it should say: hey budd go to our website canada.mydomain.com
  • If I come from Canada and I enter canada.mydomain.com it shouldn't say nothing you are already in canada internet friend
  • If I come from Canada and I enter uk.mydomain.com it should say: hey budd go to our website canada.mydomain.com

Thats it! if ideas welcome.



Mike

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Intesting plugin
« Reply #1 on: March 23, 2018, 02:41:46 AM »
@orisa

your question is really nice. but this script will not work for subdomain.

If you will check popular sites like : https://craigslist.co.in/ then this will redirect to city wise but if you will go with citywise subdomain of this site. then it will stay on same city subdomain not redirect to others.


Osclass Support Forums - Rackons.in

Re: Intesting plugin
« Reply #1 on: March 23, 2018, 02:41:46 AM »

Osclass Developer

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Intesting plugin
« Reply #2 on: March 23, 2018, 08:39:27 AM »
Try Below code in index.php of your public_html Root and change countries code and subdomain name as per your requirement


Code: [Select]
<?php

$user_country_code 
$_SERVER["HTTP_CF_IPCOUNTRY"]; 

$site_subdomain array_shift(explode(".",$_SERVER['HTTP_HOST']));

if (
$user_country_code == "IN" && $site_subdomain != "india")
  {
  
header'Location: http://india.domain.com');
  }
else if (
$user_country_code == "US" && $site_subdomain != "united-states")
  {
  
header'Location: http://united-states.domain.com');
 }

else if (
$user_country_code != "IN" && $user_country_code != "US")
  {
  
header'Location: http://domain.com');
 }
else
  {
// Do nothing
 
}

?>

« Last Edit: March 23, 2018, 08:42:08 AM by Administrator »

orisa

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Intesting plugin
« Reply #3 on: March 23, 2018, 09:08:44 AM »
After using this code on a sub-mydomain.com it won't redirect me to visitor's country. ERR_TOO_MANY_REDIRECTS on browser.

Osclass Developer

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Intesting plugin
« Reply #4 on: March 23, 2018, 09:13:51 AM »
if you are facing error with "www" so use below code with my previous code then you will not face www error

Code: [Select]
else if ( 'www' == $site_subdomain ) {

header( 'Location: https://'.$site_subdomain.'.domain.com');

}

above code will be put before
Quote
else { condition

Final Code

Code: [Select]
<?php

$user_country_code 
$_SERVER["HTTP_CF_IPCOUNTRY"]; 

$site_subdomain array_shift(explode(".",$_SERVER['HTTP_HOST']));

if (
$user_country_code == "IN" && $site_subdomain != "india")
  {
  
header'Location: http://india.domain.com');
  }
else if (
$user_country_code == "US" && $site_subdomain != "united-states")
  {
  
header'Location: http://united-states.domain.com');
 }

else if (
$user_country_code != "IN" && $user_country_code != "US")
  {
  
header'Location: http://domain.com');
 } 

else if ( 
'www' == $site_subdomain ) {

header'Location: http://'.$site_subdomain.'.domain.com');

}

else
  {
// Do nothing
 
}

?>

« Last Edit: March 23, 2018, 09:35:23 AM by Administrator »

Osclass Support Forums - Rackons.in

Re: Intesting plugin
« Reply #4 on: March 23, 2018, 09:13:51 AM »