introductioninstalling redhatunix commandsediting filesssh
sitemapapacheftptcp/ipmisc-notesresources
back  main  next
working with ssi in html pages on an apache / linux server

general concept
I'm not going to explain how to create a html page with SSI instructons. I'm assuming that you understand that already. This document is all about how to deploy and maintain html documents containing SSI instructions in a Linux / Apache environment.

what has been modified on the server to accomodate ssi
The ability ot run SSI is built into Apache, but turned off by default. Usually when SSI is turned on, you need to name files using SSI "something.shtml". I am using a method called XBitHack. This is much more elegant and also transparent to site visitors. It allows you to use SSI without changing the default .html file extension, so you won't break existing bookmarks and generally because it is more convenient for you.

how it works
When a visitor requests a page from our server, Apache checks the file attributes of that page. Specifically looking to see if Apache sees the execute attribute is set for the owner of the page in question. If it is not set, Apache dishes out a standard html page, ignoring SSI code. If the execute attribute is set for the owner apache scans the html code for SSI code, parses the SSI code,creates a static html page on the fly and sends it to the visitor.

what you need to do to make ssi work with the xbithack method
All pages containing SSI code must be set to read, write, execute for owner and group, and read, execute for others. You can check or change the files attributes by right clicking a file and selecting properties (windows) or set file attributes (mac). You cannot change the files attributes if you are not the owner of the file, but if you have write privilages, you can delete the file and upload your own, thus giving you the ability to change the files attributes. That is all you need to do when uploading a brand new file.

working with existing files that contain ssi
If you need to modify the html code in a page that contains SSI, just do it.
If you need to change part of the SSI itself (example: globally changing a nav bar that is included via SSI, but not any of the html code in the pages that use it), then life get's more complicated.

explanation
When Apache dishes out a page that contains SSI, it looks at the file modification time of the html file that has the SSI embeded and sends that date & time stamp to the visitor requesting the file. When a browser is surfing our site, it compares the date & time stamps of files in it's cache to the date & time stamps of the files that are sent by Apache. Unless the file requested is indicated as being newer than the cached file, the browser will use it's cached copy instead. So if you update a SSI, you must update the html file that uses it or it will not show up on any browser that has cached the pages in question.

how do i get around this problem
It's actually pretty easy, but you need to be carefull about what you do here. You need to change the date & time stamp of the html file that is using your newly changed SSI in question. You could do a save as on the html file and give it the same name, then upload the file. That is extra work and might lead to replacing files with incorrect versions. So here is the Unix command to modify the date & time stamp, using secure shell's teminal window. The command is called "touch". Example: If I wanted to change the date & time stamp of a file in the "example_site" directory called index.html, I would do this: "touch example_site/index.html". This will give the file new modification times from the time the "touch" command was issued and cause web browsers to download it instead of using cached copies of the file. You can of course use relative paths with this command. If you are in the "example_site" directory, just issue this command: " touch index.html".

what if I need to update more than one file using ssi in the same directory
That is pretty easy. cd into the directory in question and do this: "touch *". This will touch all files in the directory. It will not do it recursively, so if you are updating a site's nav bar and there are folders within your site, you need to do this for all folders in question one at a time as long as the nav bar is on all pages within all folders.

warning: Because you need to update the date & time stamp of files using a SSI that has been modified, please be cautious to not "touch" files that are not affected by the SSI in question. This is important as any files that you touch will be downloaded by visitors instead of using cached copies. Cached copies not only speed up the browser that is viewing your site, they also reduce traffic and load on the server increasing it's performance as well.

summary SSI can be an easy way to include small amounts of dynamic content in your web pages. It is by no means a replacement for cgi. Using SSI in web pages is relatively easy but requires attention to detail when changing a SSI component and testing all pages concerned to verify proper function.

reference material: http://httpd.apache.org/docs/howto/ssi.html