Skip to main content

Recipe for Apache's mod_rewrite and www independence

Note that ww.domainname and wwww.domainname work just as well, so if you define these in your DNS, people who make a typoe will still reach you. With a little more work, you can redirect them to either www.domainname or plain domainname without any w’s at all.

UseCanonicalName Off

LogFormat "%V %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\"" vcommon
CustomLog logs/access_log vcommon

RewriteEngine on
RewriteLog "/var/log/httpd/rewrite_log"
RewriteLogLevel 0

RewriteMap lowercase int:tolower

RewriteCond %{REQUEST_URI} ^/icons/
RewriteRule ^/(.*)$ /var/www/$1 [L]

RewriteRule ^(.+)$ %{lowercase:SERVER_NAME}$1
RewriteRule ^w*\.(.+)/(.*)$ /var/www/virtual/$1/$2 [L]
RewriteRule ^(.+)/(.*)$ /var/www/virtual/$1/$2 [L]

Et viola! Dump a website’s files in /var/www/virtual/domainname/ and define a DNS entry for it, and she’s apples. For the terminally lazy (like me), you can even define a wildcard A-record so all you need to do to add a site is dump a directory full of files in /var/www/virtual/.

For the ultimate in laziness, add a “www” directory to the new-user skeleton and make the RewriteRule path /home/$1/www/$2 instead. Now adding a new domain involves “useradd domainname and “passwd domainname (or do the same through webmin).

Another interesting trick is to hand out your favicon.ico image to every site hosted on the machine by first providing an ErrorDociment just for the icons:

<Files favicon.ico>
ErrorDocument 404 /favicon-fallback.ico
</Files>

...then defining a RewriteRule to point every site’s /favicon-fallback.ico URI to your common favicon.ico (put this in front of the RewriteRule above if you’re using both):

RewriteCond %{REQUEST_URI} ^/favicon-fallback.ico
RewriteRule ^/(.*)$ /var/www/virtual/yourmainwebdomain/favicon.ico [L]

Comments

Popular posts from this blog

every-application-is-part-of-a-toolkit at work

I have a LibreOffice Impress slideshow that I wish to turn into a narrated video. 1. export the slideshow as PNG images (if that is partially broken — as at now — at higher resolutions, Export Directly as PDF then use ‘pdftoppm’ (from the poppler-utils package) to do the same). 2. write a small C program (63 lines including comments) to display those images one at a time, writing a config file entry for Imagination (default transition: ‘cross fade’) based on when the image-viewer application (‘display,’ from the GraphicsMagick suite) is closed on each one; run that, read each image aloud, then close each image in turn. 3. run ‘Imagination’ over the config file to produce a silent MP4 video with the correct timings. 4. run ‘Audacity’ to record speech while using ‘SMPlayer’ to display the silent video, then export that recording as a WAV file. 4a. optionally, use ‘TiMIDIty’ to convert a non-copyright-encumbered MIDI tune to WAV, then import that and blend it with the speech (as a quiet b

new life for an old (FTX) PSU, improved life for one human

the LEDs on this 5m strip happen to emit light centred on a red that does unexpectedly helpful things to (and surprisingly deeply within) a human routinely exposed to it. it has been soldered to a Molex connector, plugged into a TFX power supply from a (retired: the MoBo is cactus) Small Form Factor PC, the assorted PSU connectors (and loose end from the strip) have been taped over. the LED strip cost $10.24 including postage, the rest cost $0, the PSU is running at 12½% of capacity, consumes less power than a laptop plug-pack despite running a fan. trial runs begin today.

boundaries

pushing the actual boundaries of the physical (not extremes, the boundaries themselves) can often remove barriers not otherwise perceived. one can then often resolve an issue itself, rather than merely stonewalling at the physical consequences of the issue.