Beef up your second instance of thttpd with redirects and Server Side Includes
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. You might also find Articles/GeneralThttpdSSL useful for your web server.
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.
The relevant parts of /etc/thttpd2.conf read:
port=81 nochroot # cgi! user=nobody # cgi! dir=/mnt/share/www # this is our server root cgipat=/cgi-bin/*.cgi charset=utf-8
Change your configuration accordingly, and run
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 /etc/init.d/thttpd2 restart
You can't redirect index.html with thttpd; but you can redirect "dirname/".
If you want to include a file, it needs to be in the same directory as the file it's loaded into.
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 /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.
http://hvkls.dyndns.org/downloads/documentation/ makes heavy use of the technique described here.
cd /mnt/share/www # this is our server root mkdir docs cd docs echo '<!--#echo var="LAST_MODIFIED" -->' > mod.txt # create new!! 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.