Using SSI (Server Side Includes) with domain aliases

I had several domain aliases and wanted to show a different html page based on the domain visited. Since these sites are all very similar, I wanted to share images and other content between them. I also wanted to be able to update the content in only one location. After some research, I determined that SSI could do exactly what I needed.

Add lines to your .htaccess file

Options +Includes
AddType text/html .shtml
AddHandler server-parsed .html .shtml
DirectoryIndex index.shtml index.html index.php

Enter the following in your index.html file

<!–#if expr='”$HTTP_HOST” = “domain1.tld” || “$HTTP_HOST” = “www.domain1.tld”‘–>
<!–#include virtual=”domain1.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain2.tld” || “$HTTP_HOST” = “www.domain2.tld”‘–>
<!–#include virtual=”domain2.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain3.tld” || “$HTTP_HOST” = “www.domain3.tld”‘–>
<!–#include virtual=”domain3.html” –>
<!–#elif expr='”$HTTP_HOST” = “domain4.tld” || “$HTTP_HOST” = “www.domain4.tld”‘–>
<!–#include virtual=”domain4.html” –>
<!–#include virtual=”NoneOfThese.html” –>

Explanation of above:

Options +Includes Turn on includes
AddType text/html .shtml Recognize .shtml file extension
AddHandler server-parsed .html .shtml Process both .html and .shtml for SSI
DirectoryIndex index.shtml index.html index.php Display index pages in this order

You can find many resources online that will explain all the features of SSI. Here, I am only looking to say “if the domain visited is or, then show X.html”.

Breakdown of SSI index.html

<!–# … –> Process for SSI
<!–#if expr=’ … ‘–> Start ‘If’ evaluation. If … is true, then execute next action
“$HTTP_HOST” String value for current domain name
“$HTTP_HOST” = “domain1.tld” Value of ‘True’ if current domain is domain1.tld
|| ‘Or’ operation. If either is true, then result is true
include virtual=”domain1.html” Insert content from domain1.html
<!–#elif expr=’ … ‘–> If nothing true yet, then continue checking elseif lines
<!–#else–> If noting was true, then execute next line
<!–#endif–> Stop processing this ‘If’ statement


Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Please enter 10 numbers for Captcha: * Time limit is exhausted. Please reload the CAPTCHA.