Skip to main content

Improving Apache's canonical hostname rewrite rules

· 2 min read

According to the Apache URL rewriting guide, the way to handle Canonical Hostnames is like this:

RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]

Well, those rules are not always sufficient. Specifically, what if you also owned the www.example.com.au domain, and wished to redirect it also to the primary www.example.com domain? The solution is simple - we just need to add a single $ character to the end of the match-pattern of the first RewriteCond like this:

RewriteCond %{HTTP_HOST}   !^fully\.qualified\.domain\.name$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R]

Now that will work nicely as long as the hosts use standard ports (ie 80 for HTTP, and 443 for HTTPS). However, some Python versions unnecessarily append the standard HTTPS port number to the Host HTTP header. Also I discovered today (after some Apache debug logging) that Adobe AIR applications have the exact same misbehavior for HTTPS, but only when running under Mac OS X.

My new Drupal theme

· 2 min read
Drupal site logo

I've thought about creating my own Drupal theme for this site for sometime now, but haven't really found the time and motivation to get started. That is, until my friend Mike recently radically altered his blog by creating his own Drupal theme. Well, that inspired me to finally have a go at replacing this site's much-loved default "Garland" theme.

Well, after some initial head-scratching, I was pleasantly surprised to find out just how easy it can be to theme Drupal sites! My new theme, for example, is done entirely with three CSS files, and two images.

PDF Alchemy

· 2 min read
PDF Alchemy logo

PDF Alchemy is an interesting new service that I've helped to build. It's a PDF conversion service aimed at developers - that is, it's entirely API based, and not intended for end users. But what makes PDF Alchemy interesting to me, is the way it uses a number of Amazon's cloud services.

To start with, the PDF conversion servers themselves run on Amazon EC2. EC2 is an excellent match here, since it allows PDF Alchemy to easily, and rapidly, scale to handle almost any possible volume, but also to then scale back again during off-peak periods.

svn: No newline at end of file

· 4 min read
Subversion logo

If you've used Subversion for any significant length of time, then you've probably run into the following message (or one just like it), near the end of a svn diff command.

\ No newline at end of file

Of course, you would have realised that this is because your editor has added a newline character to the end of the file in question, where the original had no such newline character.

Getting binary LOBs from DB2 via the command line

· 4 min read
IBM DB2 logo

Sometimes you just want to extract a single BLOB from a DB2 database... you don't want to write any software... you don't want to pull out some scripting language with a true DB2 database driver binding... you just want to get a BLOB from the database, and write it to a file - using nothing but the command line.

Well, there are two ways, that I know of, to do so. The first one, is the officially "correct" method, and should always work. The second method is even easier, but only works for very small BLOBs (which is all you need sometimes).

Using PyODConverter with non-default ports

· 2 min read

I've been using the excellent PyODConverter (aka Python OpenDocument Converter) for quite some time now. It's a very small Python script that uses OpenOffice's Python-UNO bridge to convert documents between formats. For example, to convert test.doc to a PDF file, you could execute:

python DocumentConverter.py test.doc test.pdf
tip

For the Python-UNO bridge (and thus PyODConverter) to work, you do need to use the python binary that installs with OpenOffice, so you will most likely need to full-qualify the python command like:

/opt/openoffice.org3/program/python DocumentConverter.py test.doc test.pdf

Anyway, PyODConverter always tries to talk to OpenOffice via (the somewhat arbitrary) port 8100. But today I found myself needing to able to tell PyODConverter which port to use via the command line. So, I went about modifying the PyODConverter code - which was very easy, thanks to it being already very well written.

Finding the local IP address with ifconfig and sed

· 3 min read

There are many ways to determine local IP addresses on Linux platforms. They almost always involve piping ifconfig into a number of grep, awk, cat, and/or tr commands.

Well, my new favorite approach is to pipe ifconfig into a single sed command :)

ifconfig | sed -n -e 's/:127\.0\.0\.1 //g' -e 's/ *inet addr:\([0-9.]\+\).*/\1/gp'

Neat, huh?! :)

So, how does it work? Well, there are two filters (aka scripts, ie the parameters after the -e flags). The first one, 's/:127\.0\.0\.1 //g', simply strips out all occurrences of the local loopback address (127.0.0.1) - this can be left out if you want to include the loopback address in the results. And the second filter, 's/ *inet addr:\([0-9.]\+\).*/\1/gp' matches all lines with IP addresses, strips all but the IP address itself, and prints the matching line (note the p at the end of the filter, which works in with the -n flag at the start of the sed command).

Signing S3 HTTP upload policies via the command line

· 2 min read

When creating HTTP web forms to allow browser-based uploads to an S3 bucket, you need to create and sign upload policies. Now if that statement lost you, then you should read over either of the following introductions to browser-based uploads to S3:

Solid State Media PC build: Part 1

· 10 min read
Media PC

As a mentioned back in this post, I am building a completely solid-state, dual-core, 64-bit media PC. I won't go into any of th "planning" details here (refer back to the original post for that). However, this post will show some of the progress so far (using lots of pics), and give some idea of the project's feasibility :)

So, without any further distraction, let's bring on the pictures!! :)

First up, we have the case... it's a Thermaltake Lanbox HT, and I must say, I am quite impressed with the build quality of this case! :)

Restoration of DB2 online backups with shipped logs

· 3 min read
abc

During the past three years, I've often been amazed at just how difficult it can be to get IBM's DB2 to successfully restore from its own backups. Even in the most simple case ( offline backups, with circular logging) you can run into difficulty, but it can be incredibly difficult if the database has been configured to use log shipping, and especially if the backups were taken "online" - that, it seems, can be most the difficult DB2 backup / restore scenario. And, of course, DB's error messages usually offer very little (to the untrained eye) to explain what's going wrong.

However, over time, I have finally figured out most of the problems, and so most restorations work quite smoothly for me now. So, I thought I'd quickly share the most useful (for me) backup and restore commands.