Difference between revisions of "Beef up your second instance of thttpd with redirects and Server Side Includes"

From NAS-Central Buffalo - The Linkstation Wiki
Jump to: navigation, search
(No difference)

Revision as of 12:43, 7 July 2006

This article Based on work by andre. Originally by andre.

Server Side Includes (SSI) and Redirection with thttpd

SSI is code executed by the server before a page is delivered. For example, you could automatically include a footer into an HTML document, or display its path and modification date.

Redirection means you request one document and are served another.

thttpd is the web server that comes with the Linkstation; the example configuration will assume you're using the second instance thttpd2, as described in Articles/GeneralThttpd.


Thttpd comes with two auxiliary programs, "redirect" and "ssi", which we'll use to serve ".shtml" pages (as SSI enabled pages are usually called).

This example configuration for an LS1 will serve web content with from /mnt/share/www. On the LS2, you will probably use /mnt/hda/share/www instead.

  • On Debian, the programs "redirect" and "ssi" reside in /usr/lib/cgi-bin/ if "thttpd-util" is installed.
  • On OpenLink, you will need to locate these programs yourself for the time being.
mkdir /mnt/share/www # this is our server root
mkdir /mnt/share/www/cgi-bin
mkdir /mnt/share/www/ssi
cp /usr/lib/cgi-bin/redirect /mnt/www/cgi-bin/redirect.cgi # on Debian
cp /usr/lib/cgi-bin/ssi /mnt/www/cgi-bin/ssi.cgi # on Debian
touch /mnt/share/www/cgi-bin/.redirects

The relevant parts of /etc/thttpd2.conf read:

nochroot # cgi!
user=nobody # cgi!
dir=/mnt/share/www # this is our server root


You cannot redirect index.html with thttpd!!!

Having said that, we want to redirect users to the linkstationwiki.net if they click on the file "community.html" on our website; linking to this file is possible.

cd /mnt/share/www # this is our server root
mv community.html 2>/tmp/ # make sure there's no offending file
ln -s cgi-bin/redirect.cgi community.html
echo '/community.html http://linkstationwiki.net' >> cgi-bin/.redirects

See "man redirect" for more information (good luck, it was the reason why I wrote this document)

Server Side Includes

We want to display the modification date of "mod.txt" in the directory "docs" on our web server automatically. Of course this also works for HTML documents, this is just an example.

cd /mnt/share/www # this is our server root
mkdir docs
cd docs
echo '<!--#echo var="LAST_MODIFIED" -->' > mod.txt # create the file
mv mod.txt ../ssi/mod.shtml
ln -s ../cgi-bin/redirect.cgi mod.txt
echo '/docs/mod.txt /cgi-bin/ssi.cgi/ssi/mod.shtml' >> ../cgi-bin/.redirects

See "man ssi" for details and more variables, how to include files, and more about SSIs.