View Single Post

  #5 (permalink)  
Old 05-04-2008
HansH
 
Posts: n/a
Default Re: mod_rewrite/alias confusion

"drhowarddrfine" <robbelics@gmail.com> schreef in bericht
news:817e5f36-1b8a-4ed2-b90e-89c88c1bd434@b1g2000hsg.googlegroups.com...
> On May 4, 2:09 pm, drhowarddrfine <robbel...@gmail.com> wrote:

A small note on the subject:
mod_rewrite modifies the mapping of an url to the filesystem to a lot wider
extend then mod_alias. The latter only unconditionally changes the mapping
for a complete folder.

>> So this is what I have so far and it partly does what I want:

Not sure whether you have full control over Apache or just only are twisting
it via .htaccess. Unfortunately the two have slightly different syntax and
behaviour... Assuming you are using a .htaccess at the root of the site.

>> RewriteEngine on
>> RewriteRule ^/?(.*)$ cgi-bin/test [L]
>>
>> I don't think that's what I want to run with because I think a problem
>> could come up with it matching everything, including impossibly long
>> or obscure matches. Another problem is that it also matches image
>> extensions, css stylesheets, javascripts and anything else I don't
>> need to serve dynamically.

Be more selective, example given only do html by:
RewriteEngine on
RewriteRule (.*\.html)$ cgi-bin/test [NC,L]

Note the NC for no(t) case-sensitive matching.

You might consider testing presence of static content before giving dynamic
response:
RewriteEngine on
RewriteCond %{ REQUEST_FILENAME} !-f
RewriteRule (.*\.html)$ cgi-bin/test [NC,L]
(Might be handy for error documents ... )

Running .htaccess based rewrites has a performance penalty.
To minimize the effect, consider setting up folders like
\images
\scripts
\test
The latter will hold hardly no files, but at least a .htaccess reading like
RewriteEngine on
RewriteBase /
RewriteCond %{ REQUEST_FILENAME} !-f
RewriteRule (.*\.html)$ cgi-bin/test [NC,L]

> I forgot to add that I changed the rewrite rule to this:
> ^([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)$ cgi-bin/test [NC,L]
>
> But it doesn't work at all.

It does work, but the way you want it ;-)
It only matches a path like /a_B/bC/C_d, but NOT /a_B/bC/C_d.html.
Notice all dynamic urls MUST BE exactly 2 levels below the site's root.


HansH
--
http://httpd.apache.org/docs/2.2/rewrite/
"Despite the tons of examples and docs,
mod_rewrite is voodoo.
Damned cool voodoo, but still voodoo."