Making Mod_rewrite's RewriteCond relative
===

Good day,

I have done a lot of searching on this but can't get a definitive answer.

I have a setup of directories:

/var/www/html/alpha/beta/cache/delta

I want a url like this:

    http://localhost/alpha/beta/delta

to look in cache/, see the delta directory exists, and forward the user there. On the other hand if the delta directory (or included index.html) did not exist, then forward the user to localhost/alpha/beta/index.php

Here is my htaccess file which rests in alpha/beta/

    RewriteBase /alpha/beta/

    # this next line is included because localhost/alpha/beta/ was forwarding to cache/
    # there is probably a better way
    RewriteCond $1 \w{1}
    RewriteCond %{DOCUMENT_ROOT}/alpha/beta/cache/$1 -d
    RewriteRule ^(.*)$ cache/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^.*$ index.php

This works (pretty much*) but I don't want this. I would like relative paths so people who use the software do not have to tinker with the included .htaccess file.

I thought RewriteBase would affect the RewriteCond but it does not. If I remove the %{DOCUMENT_ROOT} then the conditional apparently tries to match against alpha/beta/cache/delta on the file systems / directory. Using

    RewriteCond cache/$1 -d

also is not checked against the relative directory.

I cannot use {REQUEST_URI} in the conditional because then I get /var/www/html/alpha/beta/delta/cache/delta/

I cannot find way to isolate the current subdirectory for use in the conditional without it including the request.

Please help. I am at the end of my rope.

* If I use alpha/beta/delta/ all is well. But if I leave off the final forward slash, the address changes to alpha/beta/cache/delta/. I want to use the directory, but I do not want to change the url.
