Hi, I have two domains pointing to one hosting account. Let's call them: domainA.com domainB.com domainB.com is parked on domainA.com. So if you go to either domain, the same content is displayed. However I want it set so if you go to domainB.com you are redirected to domainB.com/mydirectory I have tried this using .htaccess and it doesn't work. It might be interfering with the content management system on the site. So I was hoping to achieve the same result using PHP. I found some code that almost works, but it creates a loop: <?php $domain = $_SERVER["HTTP_HOST"]; if (($domain == "domainB.com") || ($domain == "www.domainB.com")) { header("location: /mydirectory"); } ?> Can I add something to this script that effectively says "if someone enters the site using the domainB.com then redirect them to domainB.com/mydirectory unless this has already happened"?
May be this will help you <?php $domain = $_SERVER["HTTP_HOST"]; $fullpath=explode("/",$_SERVER["REQUEST_URI"]); if ( (($domain == "domainB.com") || ($domain == "www.domainB.com") ) && !in_array('mydirectory',$filepath)) { header("location: /mydirectory"); } ?>
Yes - except that you wrote "$filepath" in the second last line. I changed this to $fullpath and it works. Brilliant, excellent. Problem solved. Thanks.