Ok so I tried changing to this:
$referer = $_SERVER['HTTP_REFERER'];
if ($referer != '/mydomain2/' || $referer != '/mydomain3/' ) {
  header('Location: index2.php');
}; 
and also this:
$referer = $_SERVER['HTTP_REFERER'];
if ($referer != '/mydomain2/' || $referer != '/mydomain3/' ) {
  header('Location: index2.php');
} else{
      header('Location: index.php');
}; 
Neither change the behavior.
I then tried:
$referer = $_SERVER['HTTP_REFERER'];
if (preg_match($referer != '/mydomain2/' || $referer != '/mydomain3/' )) {
  header('Location: index2.php');
} else{
      header('Location: index.php');
}; 
but this gives a browser error that it is redirecting in a way that will never complete.

 














