Re: [Lurker-users] Lurker 2 feedback and various questions
Brought to you by:
terpstra
From: Julian M. <ju...@me...> - 2011-07-02 09:23:03
|
Wesley & Jonas, five years ago I wrote in this thread ... http://www.terpstra.ca/lurker/message/20060426.192614.7b0ef322.en.html : > The Apache 2 docs have to say the following about per-directory > RewriteRules: > > | Unbelievably mod_rewrite provides URL manipulations in per-directory > | context, i.e., within .htaccess files, although these are reached a > | very long time after the URLs have been translated to filenames. It > | has to be this way because .htaccess files live in the filesystem, so > | processing has already reached this stage. In other words: According > | to the API phases at this time it is too late for any URL > | manipulations. To overcome this chicken and egg problem mod_rewrite > | uses a trick: When you manipulate a URL/filename in per-directory > | context mod_rewrite first rewrites the filename back to its > | corresponding URL (which is usually impossible, but see the > | RewriteBase directive below for the trick to achieve this) and then > | initiates a new internal sub-request with the new URL. This restarts > | processing of the API phases. > | > | Again mod_rewrite tries hard to make this complicated step totally > | transparent to the user, but you should remember here: While URL > | manipulations in per-server context are really fast and efficient, > | per-directory rewrites are slow and inefficient due to this chicken > | and egg problem. But on the other hand this is the only way > | mod_rewrite can provide (locally restricted) URL manipulations to the > | average user. > > That's why I'd like to avoid them. > > I researched the issue, and in a per-server RewriteRule, > %{REQUEST_FILENAME} oddly does NOT contain the filename as mapped by > the "/lurker" Alias, but only the URI path, e.g. "/lurker/splash/index > .en.html". It seems that the Alias is NOT processed before the > per-server RewriteRule. > > So as far as I can see, the following is the only way to avoid a per- > directory RewriteRule. Note that I have split the /var/www/lurker > frontend cache into several caches into /var/lib/lurker/www/<frontend>. > > ScriptAliasMatch ^/lurker/((lurker|jump|keyword|bounce)\.cgi)$ /usr/lib/cgi-bin/lurker/$1 > Alias /lurker /var/lib/lurker/www/<frontend> > RewriteCond /var/lib/lurker/www/<frontend>/$1 !-s > RewriteRule \ > ^/lurker/((attach|list|mbox|message|mindex|search|splash|thread|zap)/[^/]+)$ \ > /lurker/lurker.cgi \ > [L,PT,E=LURKER_CONFIG:/etc/lurker/lurker.conf,E=LURKER_FRONTEND:/var/lib/lurker/www/<frontend>/$1] > > Does anyone know a nicer way to avoid a per-directory RewriteRule? I have now figured out how to avoid having to specify the frontend path more than once and also avoid a per-directory RewriteRule (and thus the performance penalty): ScriptAlias /lurker-cgi/ /usr/lib/cgi-bin/lurker/ RewriteRule ^/lurker/(.*)$ - \ [E=LURKER_CONFIG:/etc/lurker/lurker.conf,E=LURKER_FRONTEND:/var/lib/lurker/www/<frontend>/$1] RewriteCond %{ENV:LURKER_FRONTEND} !-s RewriteRule ^/lurker/(attach|list|mbox|message|mindex|search|splash|thread|zap)/[^/]+$ /lurker-cgi/lurker.cgi [L,PT] RewriteRule ^/lurker/ %{ENV:LURKER_FRONTEND} [L] Feel free to add that to Lurker's docs and/or apache.conf. -Julian |