this is in place here for

edit the template index.php file and add the following AS THE VERY FIRST LINES of the install's primary index.php.

$domain = $_SERVER["HTTP_HOST"];
$url = $domain . $uri;

if (($url == "") ||
   ($url == "")) { 
   header("Status: 301 Moved Permanently");

Here's the benefit: The visitor will now be redirected to the appropriate Red Site page, that has the Red Template assigned to it only in the case where they have arrived at the 'red site' domain name. Otherwise, the conditional PHP rule is ignored, and the Yellow Site loads.

Copied from here: joomla redirect how to