29 Nov 2002 Rich   » (Master)

Folks on #apache (irc.openprojects.net) have frequently asked a question that goes something like this:

I know how to make the url http://foo.com/~user go to the user's home directory, but how do I make that happen without the ~, which looks unprofessional?

There are two standard answers to this. One, you tell them that it can't be done without creating an Alias for every user, which is technically correct. The other answer is to tell them to write some sort of magic handler that knows what users are out there, and maps requests to the correct directory. Perhaps in mod_perl?

Well, over the last few weeks, I have been doing a number of the things that I have been telling folks on #apache to do, or things that I have long claimed were trivial, and I just had not gotten around to them yet. For example, I keep saying that you can write an Apache access control thingy that would restrict access based on the phase of the moon. So last week I wrote one.

So, anyways, here is the mod_perl thing that creates magic user alises for users so that http://foo.com/user/ goes to that user's home directory. It was depressingly easy.

<Perl>
# Folks you don't want to have this privelege
my %forbid = map { $_ => 1 } qw(root postgres bob);
opendir H, '/home/';
my @dir = readdir(H);
closedir H;
foreach my $u (@dir) {
    next if $u =~ m/^\./;
    next if $forbid{$u};
    warn "$u/public_html";
    if (-e "/home/$u/public_html") {
        push @Alias, "/$u/", "/home/$u/public_html/";
    }
}
</Perl>

Yeah, that's all there is to it.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!