AliasMatch gotcha

I don’t use Apache’s AliasMatch directive often, and when I do, I tend to use it incorrectly on the first try for some strange reason.

Wrong – infinite loop!

AliasMatch ^/apps/([^/]+)/media/ /opt/django/apps/$1/media/

Right:

AliasMatch ^/apps/([^/]+)/media/(.+) /opt/django/apps/$1/media/$2
Advertisements

  1. #1 by Ölbaum on March 4, 2010 - 6:37 pm

    Thank you so much, it’s beeen driving me crazy for an hour trying to set-up Trac with multiple projects.

    I don’t understand why the wrong one gives an infinite loop, though. AliasMatch translates a URI to a file name, so 1. there’s no reason it should try and alias the result again and 2. the result /opt/django/apps/foo/media/ does not match the regex ^/apps/([^/]+)/media/ as it does not start with /apps.

    Where am I wrong?

  2. #2 by David Chandek-Stark on March 5, 2010 - 9:24 am

    Yeah, I don’t really know why the loop happens. As you say, it seems that it shouldn’t. I haven’t tried this recently, so don’t recall the exact behavior. Maybe there was/is a bug in Apache (2.2)?