Drofmij

Hello my name is Jim and I'm a software developer. You can find me on twitter as @originaldrofmij.

Simple SSI Blog

What better way to rock a retro internet community page then to build it with a vintage web technology?

<!-- This is my complete index.shtml -->
<!--#include virtual="../include/html5start.shtml"-->
<!--#include virtual="../include/headcontent.shtml" -->
<!--#include virtual="../include/analytics.shtml" -->
<!--#include virtual="../include/header.shtml" -->
<!-- Insert Content Here -->
<!--#include virtual="../include/footer.shtml" -->

Some folks in the #tildeclub IRC channel mentioned that SSI is available on the tilde.club user homepages and had to check it out. From what I can gather after a quick google search, and reading this apacheweek article I discovered that SSI (Server Side Includes) have been available at least as early as 1996.

Thus began an EPIC journey of discovery and configuration that stretched me to my very limits! I banged out some quick templates on tilde.club editing LIVE FILES in the public_html folder, just like my web forefathers of epochs gone by.

After reading many forgotten tomes of curious and arcane knowledge, I found some of the answers I needed in mod_rewrite docs for .htaccess files and mod_include docs for SSI. Once I had a working (albiet very simple) set of scripts, I declared it the traditional developer status of good-enough-for-now.

# This is the .htaccess file for redirecting to index.shtml
# (apache won't process SSI by default unless your extension is .shtml

# rewrite / to /index.shtml
RewriteRule ^$ index.shtml

# rewrite folder/ to folder/index.shtml
RewriteRule ^(.*/)$ $1index.shtml

So I started polishing some things the next day. I added some nav links, I added an about page. Then I was thinking, but what if I want permalinks to blog posts (for example: tilde.club/~drofmij/blog/simple-ssi-blog)?

# check that URL is NOT directory
RewriteCond %{REQUEST_FILENAME} !-d

# check that URL is NOT a file
RewriteCond %{REQUEST_FILENAME} !-f

# make sure we have a file to redirect to with .shtml extension
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.shtml -f

# BOOM! /blog/simple-ssi-blog -> loads /blog/simple-ssi-blog.shtml
RewriteRule (.*) $1.shtml [L]

But wait, what if I want to edit this thing before I make it live? Can I run this SSI stuff on my local Ubuntu box? I was thinking "No problem, I'll just drop in the config and go." I found out it's more complicated then that. I played with config for awhile on apache with no progress, apache did not want to do SSI on my box...

The next day I figured out the difference: stock apache2 uses httpd.conf to control things, Ubuntu / Debian apache2 packages have their own config pattern (see this Control Escape article for details).

Here is what I had to do for apache 2 on Ubuntu / Debian

# Run this MAGIC command (as root):
a2enmod include

# Edit /etc/apache2/apache2.conf (as root)
# Find the  entry for /var/www/ (or your directory of choice)
<Directory /var/www/>
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>

# Add the word Includes to the Options line (edits in blue)
<Directory /var/www/>
  Options Indexes FollowSymLinks Includes
  AllowOverride All
  Require all granted
# Add the following two lines to the end of the Directory entry:
  AddType text/html .shtml
  AddOutputFilter INCLUDES .shtml
</Directory>

#Now restart apache
sudo service apache2 restart
  

So why am I writing all of this down? Well, I thought I would share this retro-futuristic code with anyone who wants it. You can eyeball the strange mashup of SSI and HTML5 on github: Simple SSI Blog.

Log in to the twitters and let me know what you think :D