Futility

So, on Thursday, I decide to try to get Apache to sneakily substitute files from another server without telling anyone (I have my reasons). I had got a vague idea of how to do this sort of thing while looking up how to automatically redirect visitors from one domain to another. I start by searching around on the Internets for a basic template on how to do this, eventually coming up with the following set of rules to go in the .htaccess file for my Woaf webspace:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/blog/.*$
RewriteRule ^.*$ http://www.axelfendersson.co.uk%{REQUEST_URI} [P,L]

It doesn’t work. Rather than substituting files from axelfendersson.co.uk and pretending they’re still coming from axelfendersson.woaf.net, it just throws up 404 errors. Now the files are still there on Dog, so the rule must be doing something, or they’d just appear as normal. I’ve already spent some time figuring out how to get this far. I then spend hours trying to figure out what I’ve done wrong. Why can’t it find the files it’s looking for? What’s going wrong? Why does it work if I replace the internal proxy with an external redirect, but not if I don’t?

After an hour or two of puzzling over this, I have to abandon my attempt to go to a data handling workshop. When this finishes, I go back to the University computer room and continue trying to figure out what I’m doing wrong. By now I have already learned more about Perl-style regular expressions than I was really interested in, but clearly I don’t know enough, because I’m still getting 404s where I should be getting my blog (but served up from a different host). More time passes.

Until I notice something in the Apache documentation that might be relevant:

Notice: To use this functionality make sure you have the proxy module compiled into your Apache server program. If you don’t know please check whether mod_proxy.c is part of the "httpd -l" output. If yes, this functionality is available to mod_rewrite. If not, then you first have to rebuild the "httpd" program with mod_proxy enabled.

Oh dear. I ssh into Dog. Can’t find the hhtpd executable anywhere, until I realise I’m looking for the wrong thing. Output of /usr/sbin/apache -l:

Compiled-in modules:
  http_core.c
  mod_so.c
  mod_macro.c
suexec: enabled; valid wrapper /usr/lib/apache/suexec

So there’s the problem. I’ve just wasted hours trying to figure out how to tell Apache to do something that it doesn’t have the necessary modules to do. Bugger.

3 Comments

  1. Actually the module is there, but it’s loaded as a DSO rather than compiled in.

    Try:
    RewriteRule ^/(.*) http://www.axelfendersson.co.uk/$1 [L,R]

    Alternatively point www.axelfendersson.co.uk at dog, and ask me to add a ServerAlias for you :P

  2. Ah, I did wonder whether that was really the full list of modules, since mod_rewrite wasn’t there either, and that obviously worked.

    Actually, I’m not really that bothered about not being able to use mod_proxy. What I did find frustrating was that I wasted 2-3 hours trying to figure out how to do it, only to find that I couldn’t.

    (Oh, and I think I tried that variant of the RewriteRule at one point, except with [P,L] instead of [L,R].)

Leave a Reply to Jonathan Cancel reply

Your email address will not be published.