.htaccess blacking a page

Discussion in 'Apache' started by bobby9101, May 14, 2006.

  1. #1
    how can i 301 redirect one person from ip say 127.0.0.1 from /anypage.php
    to /newpage.php
    but only that one ip gets redirected?
     
    bobby9101, May 14, 2006 IP
  2. Hoth

    Hoth Well-Known Member

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #2
    As far as I can see htaccess doesn't allow redirecting by IP, so you'll need to do that in the PHP file. In anypage.php:
    if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') header("Location: newpage.php");
    Code (markup):
     
    Hoth, May 16, 2006 IP
  3. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <?php
    
    if ($_SERVER['REMOTE_ADDR'] == '111.111.111.111') header("Location: index.php");
    
    require_once 'init.php';
    
    $query	= $db->Execute("SELECT * FROM {$tables['link']['name']} WHERE STATUS=2 ORDER BY RAND() LIMIT 1");
    $row	= $query->FetchRow();
    $query->Close();
    
    if ($row['ID']) {
    	$query = $db->Execute("UPDATE {$tables['link']['name']} SET HITS=HITS+1 WHERE ID=".$db->qstr($row['ID']));
    	$query->Close();
    }
    
    header("Location: " . $row['URL']);
    
    ?>
    PHP:
    it didn't work
    i replaced my ip, so that wasnt the problem.
    is the problem that
    
    header("Location: " . $row['URL']);
    Code (markup):
    is in the file twice?
     
    bobby9101, May 16, 2006 IP