1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to redirect visitors of specific countries to 404 page?

Discussion in 'White Hat SEO' started by nichkhun, Sep 28, 2013.

  1. nichkhun

    nichkhun Junior Member

    Joined:
    May 8, 2009
    Messages:
    102
    Likes Received:
    2
    Location:
    Palo Alto, CA
    Home Page:
    I want to know about methods to redirect them to 404 page.

    Have anyone help me to write or guide it?

    Thank you
     
  2. Vrill

    Vrill BANNED BANNED

    Joined:
    Jun 16, 2013
    Messages:
    380
    Likes Received:
    374
    Depends what do you prefer.To redirect by country IP or by browser language
     
  3. TZ2011

    TZ2011 Senior Member

    Joined:
    Jun 26, 2011
    Messages:
    832
    Likes Received:
    864
    Occupation:
    Cleaning servers
    Why to 404 ? 404 is " not found", people many times don't want to stay on site when desired page is not existing. You can redirect them to index page, or some offer or page made for their country. Real visitors are precious, don't just redirect them to nothing.
     
  4. nichkhun

    nichkhun Junior Member

    Joined:
    May 8, 2009
    Messages:
    102
    Likes Received:
    2
    Location:
    Palo Alto, CA
    Home Page:
    By country IP such as visitors from China & India sir.
     
  5. nichkhun

    nichkhun Junior Member

    Joined:
    May 8, 2009
    Messages:
    102
    Likes Received:
    2
    Location:
    Palo Alto, CA
    Home Page:
    I don't want they access to any page but want sent them to 404 page.
     
  6. Sep77.

    Sep77. Junior Member

    Joined:
    Jul 28, 2012
    Messages:
    191
    Likes Received:
    66
    Location:
    Europe
    Home Page:
    Here's a pseudocode (I guess you want it in PHP as most people use it - so I used the PHP convention - but in other languages it's very similar):

    1.) Get users' IP, like this:
    Code:
    [COLOR=#00008B]if[/COLOR] (!empty($_SERVER[[COLOR=#800000]'HTTP_CLIENT_IP'[/COLOR]])) {
        $ip = $_SERVER[[COLOR=#800000]'HTTP_CLIENT_IP'[/COLOR]];
    } elseif (!empty($_SERVER[[COLOR=#800000]'HTTP_X_FORWARDED_FOR'[/COLOR]])) {
        $ip = $_SERVER[[COLOR=#800000]'HTTP_X_FORWARDED_FOR'[/COLOR]];
    } [COLOR=#00008B]else[/COLOR] {
        $ip = $_SERVER[[COLOR=#800000]'REMOTE_ADDR'[/COLOR]];
    }
    2.) If you want to redirect just users from several countries, put them into an array. For more countries, use database.

    3.) Now you have IP address of the user who is on your site (step #1) and people who you want to filter (step #2), so just test, if the user from #1 is in array of blacklisted people in #2 and redirect him.

    Voilà.
     
  7. nichkhun

    nichkhun Junior Member

    Joined:
    May 8, 2009
    Messages:
    102
    Likes Received:
    2
    Location:
    Palo Alto, CA
    Home Page:
    Thank you

    I will try it
     
  8. bartosimpsonio

    bartosimpsonio Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 21, 2013
    Messages:
    8,911
    Likes Received:
    7,514
    Occupation:
    ZLinky2Buy SEO Services
    Location:
    ⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩
    Home Page:
    The country of origin is not included in the request. So you need something external to detect the country. You can either infer by the visitor hostname, such as yadayada.bla.cn would be China, or you could buy a commercial package that gives you ip geolocation and you write a simple include in PHP or your favorite language.

    Needless to say this will slow your pages down.
     
  9. Mr.Whitehat

    Mr.Whitehat Senior Member

    Joined:
    Apr 23, 2009
    Messages:
    855
    Likes Received:
    220
    Occupation:
    Wandering Around !
    Location:
    Dating Moolah Babe^
    Search for geoip redirection here. get the script edit and upload to ur root folder along with the .dat file and .inc then ya good to go
     
  10. toasia

    toasia Junior Member

    Joined:
    Jul 17, 2012
    Messages:
    187
    Likes Received:
    127
    Occupation:
    Web Development
    Location:
    Phuket Thailand
    Another way to redirect users is through a simple htaccess code. Here's the begining of the one I use to block website visitors in Thailand : All the Ip ranges need to be inserted after the code. So when visitors try to access a page of my site from Thailand they get redirected to Google.com

    You can get a specific ip range list per country from this site: countryipblocks.net

    ErrorDocument 403 http://www.google.com
    <Limit GET HEAD POST>
    order allow,deny
    # Country: THAILAND
    # ISO Code: TH
    # Total Networks: 413
    # Total Subnets:
     
  11. nichkhun

    nichkhun Junior Member

    Joined:
    May 8, 2009
    Messages:
    102
    Likes Received:
    2
    Location:
    Palo Alto, CA
    Home Page:
    Thank, Toasia

    I used this method in currently.

    However, I think if I wanted to block many countries it cause .htaccess has enough size beside other Thai which use proxies can visit as not block.
     
  12. leet0r

    leet0r Newbie

    Joined:
    Sep 27, 2013
    Messages:
    11
    Likes Received:
    1
    What about maxmind database? You tried this?
     
  13. nichkhun

    nichkhun Junior Member

    Joined:
    May 8, 2009
    Messages:
    102
    Likes Received:
    2
    Location:
    Palo Alto, CA
    Home Page:
    I don't know about maxmind database ;(
     
  14. leet0r

    leet0r Newbie

    Joined:
    Sep 27, 2013
    Messages:
    11
    Likes Received:
    1
    hmm that´s sad :p Google should help, include the maxmind geo script after that you can just Redirect visitors with code like this for example: if(country == "US") {window.location.. Website you want}