Home > Programmering > Redirect all but one IP in PHP

Redirect all but one IP in PHP

Example if you’d like to redirect all web visitors except one IP:

<?php
  if ( $_SERVER["REMOTE_ADDR"] != "192.0.0.0" ) {
      header("Location: http://otherurl.example.com");
      exit(0);
  }
?>

Or use mod_rewrite in Apache:

RewriteCond %{REMOTE_ADDR} !^1.2.3.4$
RewriteRule /?(.*)$ http://my.redirect.com/$1
Categories: Programmering Tags:
  1. No comments yet.
  1. No trackbacks yet.