[HCoop-Help] Domtool mod_rewrite: rewriteCond for existent / non-existent files

Michal michal at hcoop.net
Sun Apr 12 13:22:22 EDT 2009


I'm trying to write rewrite rules that depends on whether a file
exists. Specifically to only rewrite an URL if a file does *not*
exist. A simple example is the following. I would think the following
should only show the image '/images/home.png' when browsing to the
*non-existent* directory:

    rewriteCond "%{REQUEST_FILENAME}" "!-f" [];
    rewriteCond "%{REQUEST_FILENAME}" "!-d" [];
    rewriteRule "^/nonexistant/$" "/images/home.png" [last];

    rewriteCond "%{REQUEST_FILENAME}" "!-f" [];
    rewriteCond "%{REQUEST_FILENAME}" "!-d" [];
    rewriteRule "^/existant/$" "/images/home.png" [last];

However if shows the image when going to both directories.

I notice that the [] is required for a rewriteCond (if I omit it then
I get an error relating to mod_rewrite_cond_flag). However, I can't
find mention of a flag in the Apache docs
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteCond ,
and the Domtool reference doesn't explain either
http://hcoop.net/domtool/mod_rewrite.html#T_mod_rewrite_cond_flag .
Could it be something to do with that: am I missing some flags?



More information about the HCoop-Help mailing list