faqts : Computers : Internet : Web Servers : Apache

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

11 of 20 people (55%) answered Yes
Recently 4 of 10 people (40%) answered Yes


How does one setup access to virtual headers and footers? (embedding references to other .html docs)

May 14th, 2004 13:29
Anthony Boyd, Lester Godsey,

I like using PHP for this, but that isn't built into Apache.  You can 
enable SSI by changing httpd.conf.  First, find the area in httpd.conf 
where handlers are being added (search for "handler").  Add this line:
AddHandler server-parsed shtml
Then find the Options line used for your site, and add "Includes" so 
that it looks something like this (rough example):
<Directory "/usr/local/apache/htdocs">
Options Includes
There may be other words on the same line as "Options" -- such 
as "Indexes" or "FollowSymLinks" -- that's fine, don't wipe 'em out, 
just add "Includes" somewhere on that line.  Then save the file and 
restart the server.
Then in your HTML files, just add this line any place you want:
<!--#include virtual="../myfile.html" -->
Be sure to change myfile.html to the name of the file you want to 
include.  And make sure the path is correct.  That's it.
Anthony's UPDATE on May 14, 2004:
If you have difficulty with what I wrote above, it may be that I left
out one VERY important point: any HTML file that uses this trick (the
whole "<!--#include stuff" line) must be renamed to have a .shtml file
extension.  So let's say you have header.html, and you want your
index.html file to use it.  You would add this line to index.html:
<!--#include virtual="header.html" -->
Then you would rename index.html to be index.shtml (why?  because Apache
is set to only allow .shtml file to do this stuff).
Anthony's SECOND UPDATE on May 14, 2004:
For anyone who is using a server that CAN do PHP, here is a quick
walkthrough on using PHP to include files.  As in the previous example,
let's say you have header.html, and you want your index.html to use it.
You would add this line to index.html:
<?php include_once("header.html"); ?>
Then, rename index.html to be index.php.  When you pull up index.php in
your Web browser, everything in header.html should show up.  If it
doesn't, you'll need to be sure the path to header.html is correct, and
you'll need to be sure that .php is the correct extension for files that
can do this stuff (try .phtml or .php3 as alternate file extensions that
might work).  If it still doesn't work, it's possible you don't have PHP
enabled on the server.