divider

PHP Redirect Based on URL

Services: Law Firm Website Design . SEO . Internet Marketing . Law Firm Marketing Guide . Content Marketing . PPC

Ever want to send a user to a different part of your web site, based on what domain they use? Find out how.

You can redirect a visitor to another page on your site based on the domain they are using. This is useful if a company has multiple domains and multiple page addresses. For instance for DefenseGroup.com, they have a Spanish domain called GrupoDefensor.com. For those clients that use that domain, we want to redirect them into the Spanish part of the web site automatically. Here is how we did it with five lines of code and a simple IF statement.

if (($_SERVER[‘HTTP_HOST’] == “grupodefensor.com”) || ($_SERVER[‘HTTP_HOST’] == “www.grupodefensor.com”))
{
header(‘Location: index-sp.php?category=Abogados+de+Defensa+Criminal’);
}
?>

The code asks the PHP server to see what the HTTP_HOST header is (line 2/3). If it is groupdefensor.com or www.grupodefensor.com, then it redirects to the Spanish part of the site (line 4/5). If not, then the code is just skipped and continues to load the rest of the PHP code on the page. Simply place this code in the top of any page that you want to redirect and you can start redirecting users around your site..


Related Posts