<?php $urlarray = explode('.', $_SERVER['HTTP_HOST'); $subdom = $urlarray[count($urlarray) - 2]; switch ($subdom) { case 'subdomain': header("Location: location1.html"); break; case 'subdomain2': header("Location: location2.html"); break; default: header("Location: index.html"); } ?> Code (markup): I am trying to get it to automatically redirect to a different place based on subdomain
Why not just use htaccess with hostname? It would make it easier compared to using Location: index.html and having a index.php there too.
We are wanting to be able to get our members to set their own sub domains by themselves, just thought this would be an easier option for us to impletment on the site.
Also, with the above code in our index file, it is putting it'self into a loop, not sure how to get round that one.
Don't Place this code in index Files Else Remove Index.php and in the default and change it to location9.php and there setup a redirect to the index
You have a missing (closing) square bracket. That above line should read; $urlarray = explode('.', $_SERVER['HTTP_HOST']); PHP:
Thats the error. As for the not placing in index file, it is not necessary if index.html and index.php are different and index.php is set as default. that should work i guess!