Include a HTML document in another
I wanted to maintain a standard header for my website in one file and include it in my webpages. We could do this pretty neatly with Apache’s SSI (Server Side Includes).
First we need to install and enable the apache include module:
$ apt-get install apache2-common $ ln -s /etc/apache2/mods-available/include.load /etc/apache2/mods-enabled/
Then in the http config file add Options +Includes and XBitHack on to enable SSI parsing on executable html files, e.g.
<Directory /var/www/ibao.net> Options +Includes XBitHack on ...
Restart apache i.e., apache2ctl graceful
Now to include header.html in a webpage, just add:
<!--#include virtual="/header.html" -->
And we need to make the webpage executable: chmod +x webpage.html.
You could do other neat stuff with SSI, for example:
<!--#config timefmt="%D" -->
This file last modified <!--#echo var="LAST_MODIFIED" -->
inserts the last modified date in the html document.
Leave a Reply
You must be logged in to post a comment.