haggholm: (Default)

So I want to move my personal website over to mod_python, because Python is neat; but I don't want to break existing URIs. This seems like a pretty simple task—in fact, it is a pretty simple task. I just need to capture requests for .html files and run them through the Python script that does stuff.

<Directory "/my/htdoc/dir">
    AddHandler mod_python .html
    PythonHandler my_handler

Piece of cake! I've got this running on my local Apache server and it works beautifully. The only tiny issue is that for various reasons, I have a bunch of subdirectories over at petterhaggholm.net which could contain, among many other things, static HTML files that I don't want to run through mod_python. This is where things start to get hairy. I imagined that I could do something like this to apply to all subdirectories:

<Directory "/my/htdoc/dir/*">
    AddHandler None .html

The None handler would clear the mod_python handler and restore default behaviour, which is to have Apache send the static HTML. So far, so good—but the rule also applies to the base directory, /my/htdoc/dir! In other words, this second rule overrides the first and completely sabotages the mod_python rule. Worse yet, the <Directory> rules seem to match ordinary files and not just directories; for instance,

<Directory "/my/htdoc/dir/a*">
    # ...

will turn out to match /my/htdoc/dir/aboutme.html. (This is presumably why it seems to apply to the whole directory when I just use *: It matches all files /my/htdoc/dir/* instead of all directories /my/htdoc/dir/*; a trailing slash, by the way, makes no difference.) I find this rather bizarre, and I can't seem to find a way to fix it. I can circumvent it by setting up overriding rules referring to specific subdirectories, but I don't want to have to do that, and in fact I don't want my mod_python handler to apply to any subdirectories—but I do want it to apply to the root. I can do one better and fix it for files in subdirectories:

<Directory "/my/htdoc/dir/*/*">
    AddHandler None .html

This will work properly for /my/htdoc/dir/sub/index.html, but if you go to /my/htdoc/dir/sub/ it won't give you index.html, but a mod_python error message, because the request for sub/index.html within the directory /my/htdoc/dir fails! Why it interprets this as a request for sub/index.html in /my/htdoc/dir rather than a request for index.html within sub is quite beyond me.

Does anyone know a proper solution to my problem? If you help me, I will give you cake¹.

¹ The cake is a lie.


haggholm: (Default)
Petter Häggholm

April 2016

345 6789


RSS Atom

Most Popular Tags