Include html file across several pages


Hi, I use the same footer code on all my pages, and instead of copy/paste each time I change something I would like to each page to reference the same file, say, footer.html. My site map is simple: root–> page1 (folder) --> index.html
Is there a simple way to do this? Thanks.


PHP does this quite nicely:

Create one file called index.php
Create another file called footer.php

The two files are right next to each-other…same directory

in footer.php put all of your footer content

now in index.php add this line where you would normally have all of the footer stuff:

    <?php @ require_once  "footer.php"; ?>


you can do the same thing with a header file, sidebars, or whatever other content you might re-use often


Another way is to use Server Side Includes (SSI)

If you are not already firing up the PHP engine on the server, why do so? It will just add to server load. Using SSI uses a heck of a lot less server resources than PHP.

So similar to sierracircle’s suggestion, just put all the footer stuff in an html file (no need to use any or tags) and name it footer.html. Best to separate your include files from your webpages by creating a directory named /includes/ to put them all in.

Example of SSI code:

<!--#include virtual="/includes/footer.html" -->


I did exactly what you suggested. Put footer.html in a folder ‘includes’ in the directory root. Created a test page, page1.html, deleted the normal footer code and replaced it with

The footer did not show up on the page. Is there something I have to configure in the htaccess to make this work? Or any other ideas why it didn’t show up?

This solution seems more appealing to me because my pages are already saved as index.html, I don’t have anything in .php.

EDIT: I found dreamhost wiki on how shtml is parsed by default but this can overcome in htaccess, will give it a try shortly.


Ok, I looks like it works. In addition to what was mentioned above, I just needed to add to my htaccess file:

The wiki says this may impact performance/load time but I ran speed tests before and after and there was no difference whatsoever. Thanks!


Theoretically anytime the server has to perform extra steps, it impacts load time. Whether this is even measurable depends on many other factors. If your site is not employing database queries, or loading very large files, using SSI should not be noticed.

Sorry, forgot to mention the need for AddHandler (which is needed because of Dreamhost’s server config.)