trying to have a index.php file for 3 different domains… so I need to display different content for the different domains. But want it to work also on “sub folders” for sub folders I mean site1.com/some_content
this is my code but it doesn’t work as I want.
<?php
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == 'site1.com') {
echo "A LOT OF HTML JAVASCRIPT AND CSS";
}
if($host == 'site2.com') {
echo "Same here but different content";
}
if($host == 'site3.com') {
echo "Cats and flowers";
}
?>
any ideas? Thanks!
If you are using Apache, you could define something like this in your
.htaccessfile:Then, in your index.php file (or whatever you include on every page load) add this:
Afterwards, you can read the value of
APPLICATION_ENVanywhere in your code to determine what environment you are on at the moment like this:You can point multiple hostnames to the same IP/host in your /etc/hosts (or C:/Windows/System32/drivers/etc/hosts) file like this (assuming it’s on localhost):
I know having a global constant is not idea, but it’s better than relying on HTTP_HOST as that can easily be changed.