Hosting multiple domains pointed to the same web-space

Place the snippet of code in an index.php file to pull up a different web page for each domain pointed to the same web-space.

<?
$serverName = $HTTP_HOST;
$serverName = str_replace("www.",&quot;",$serverName);
$serverName = str_replace(".com",&quot;",$serverName);
$serverName = str_replace(".net",&quot;",$serverName);
$serverName = str_replace(".org",&quot;",$serverName);
if (!(empty($serverName))) {
   include("./".$serverName.".html");
}
?>

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Serve domains from sub-folders

You can also serve domains pointed to the same server space to be directed to a particular sub-folder within the main hosting account using mod_rewrite rules:

Options +FollowSymLinks
RewriteEngine On    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp;    &nbsp; 
RewriteBase /
RewriteCond %{HTTP_HOST} domain_name.tld [NC]
RewriteCond %{REQUEST_URI} !folder_name/
RewriteRule ^(.*)$ folder_name/$1 [L]

Comment