Page 5 of 8 FirstFirst ... 34567 ... LastLast
Results 41 to 50 of 78

Thread: How can i redirect bad traffic?

  1. #41
    vectro's Avatar
    vectro is offline I Like Stuff
    Join Date
    Dec 2008
    Location
    U.S.A.
    Posts
    630
    Thanks
    192
    Thanked 104 Times in 82 Posts
    Quote Originally Posted by _Chris_ View Post
    Am I able to use the .htaccess file for this at all please ?
    Probably not if it's a Perl module. Your hosting provider would need to have the Apache module for you to control it with .htaccess.

  2. #42
    Freedoom is offline Unknown Net Builder
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    I have a question, how about redirect from different countries to different sites... let me show you how I'm trying to do:

    <?PHP
    include('geoip/geoip.inc'); //this file must exist in your directory

    $gi = geoip_open('geoip/geoip.dat',GEOIP_STANDARD);

    // get the ip of the visitor
    $addr = getenv('REMOTE_ADDR');
    // translate his ip to a country code
    $country = geoip_country_code_by_addr($gi, $addr);
    // close the geo database
    geoip_close($gi);

    $badcountry = array('PT');
    // You can change the example with any countries that you want to block

    // redirect them if they suck
    if(in_array($country, $badcountry))
    header('Location: http://www.domain.com'); //enter a url or page on your site

    $averagecountry = array ('GR');

    // redirect them if they suck
    if(in_array($country, $averagecountry))
    header('Location: http://www.domain1.com'); //enter a url or page on your site

    $mediumcountry = array ('RO');
    if(in_array($country, $mediumcountry))
    header('Location: http://www.domain2.com'); //enter a url or page on your site

    $highcountry = array ('SE');
    if(in_array($country, $highcountry))
    header('Location: http://www.domain3.com'); //enter a url or page on your site
    ?>
    but I can't get it to work... I saw this code in here but I can't get it work...

  3. #43
    UncleP's Avatar
    UncleP is offline The perfect face for radio
    Join Date
    Nov 2009
    Location
    Blighty
    Posts
    217
    Thanks
    20
    Thanked 91 Times in 61 Posts
    The codes posted elsewhere on here only have a single redirect domain and they work, I use it myself. From what I can see of yours I think you need to have some else statements if using multiple if's but where I don't know, I'm not a programmer.
    If I can't be a good example, I'll just have to be a terrible warning...

  4. #44
    Mike-XS's Avatar
    Mike-XS is offline XeroAgent
    Join Date
    Sep 2009
    Location
    OZ
    Posts
    209
    Thanks
    30
    Thanked 109 Times in 71 Posts
    Quote Originally Posted by Freedoom View Post
    Hi,
    I have a question, how about redirect from different countries to different sites...
    Hi Freedom, I posted some examples you can try here: How to redirect different countries to different sites

  5. #45
    Mike-XS's Avatar
    Mike-XS is offline XeroAgent
    Join Date
    Sep 2009
    Location
    OZ
    Posts
    209
    Thanks
    30
    Thanked 109 Times in 71 Posts
    Quote Originally Posted by _Chris_ View Post
    Just had this bacvk from the hosts - &quot;We have installed the &quot;Geo::IPfree&quot; perl module on the server&quot;

    Does this change anything ?
    Ask them if they can install the GEO IP mod for Apache instead.

    If they can't or dont want to, then I made script you can try out which works without .htaccess or the geoip.dat file if it's not available. I'll post it somewhere when I get a chance.

    Instead of the geoip.dat file or .htaccess method, the script calls out to an external online GeoIP API lookup site for retrieving the country codes and then redirects or blocks visitors based on that information. Relying on an external site for redirecting/blocking people probably isn't a great idea, but it works.

    There are a few more options like using a mysql database or a flat file database where you set all the country IP's into .php files seperated by IP ranges.
    Last edited by Mike-XS; 2 May, 2011 at 13:14 PM.

  6. #46
    Freedoom is offline Unknown Net Builder
    Join Date
    May 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks.

    What is the best way? The "if else" or the "switch case select" ?

  7. #47
    Mike-XS's Avatar
    Mike-XS is offline XeroAgent
    Join Date
    Sep 2009
    Location
    OZ
    Posts
    209
    Thanks
    30
    Thanked 109 Times in 71 Posts
    The switch is probably easier to work with and modify when you want to add more countries with another block like the example below.
    switch ($country){

    // start
    case 'XX':
    header('Location: http://www.domain1.com');
    exit(0);
    break;
    // end

    }

    And just replace the 'XX' with the 2 letter country code you want to redirect.

  8. #48
    _Chris_ is offline Newbie Net Builder
    Join Date
    Apr 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Mike, there's a few 100 pages, so really need to put the code in just one place, but affecting all the pages - is that possible please?

  9. #49
    Mike-XS's Avatar
    Mike-XS is offline XeroAgent
    Join Date
    Sep 2009
    Location
    OZ
    Posts
    209
    Thanks
    30
    Thanked 109 Times in 71 Posts
    Yes, only if your server configuration permits, then you can prepend a .php file to all other .php files, with .htaccess or in php.ini.

    EG: Automatically append or prepend files in a PHP script

    I would push your host a little more though, if they are willing to install the perl mod, then maybe they can install the Apache GEOIP mod too.

  10. #50
    _Chris_ is offline Newbie Net Builder
    Join Date
    Apr 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Mike, will ask them and come back to you.

Page 5 of 8 FirstFirst ... 34567 ... LastLast

Similar Threads

  1. Non www to www redirect
    By tetrapak in forum Managing
    Replies: 8
    Last Post: 31 May, 2010, 18:19 PM
  2. [WTS] Traffic | Traffic | Traffic | Dont forget to check inside
    By squintoo in forum Services
    Replies: 2
    Last Post: 16 October, 2009, 15:12 PM
  3. 301 redirect all to all
    By Hellas in forum Managing
    Replies: 0
    Last Post: 27 August, 2009, 12:25 PM
  4. How to redirect traffic with CSF?
    By ProxySites.ca in forum Web Hosting
    Replies: 1
    Last Post: 5 August, 2009, 23:47 PM
  5. Non-www. to www. 301 redirect
    By Dr. Stavros in forum Managing
    Replies: 8
    Last Post: 29 July, 2009, 18:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •