I'm writing an .htaccess file that will check if a requested page exists in a cache or not. In order to perform the check (and save typing), I'm setting an ENV variable with the location of the cache:
# all this works as I expect #
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /some/path/
RewriteRule ^(.*)$ - [E=rewritebase:/some/path/,E=cache:%{ENV:rewritebase}cache/]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{ENV:cache}$1\.html -f
RewriteRule ^(.*)$ $1\.html [L]
</IfModule>
As you can see, I'm also having to set an ENV variable to "stand in" for the RewriteBase value. I'd rather not, since if the RewriteBase is changed, I'd have to remember change the ENV variable also. Eventually, this may be a part of a CMS used by others, which I wish to be as simple/straightforward as possible to configure, with the fewest opportunities for error. I'd like to be able to set only the ENV:cache
variable without the need for setting an ENV:rewritebase
variable, like so (or similar):
# doesn't work #
RewriteRule ^(.*)$ - [E=cache:%{RewriteBase}cache/]
As implied, the cache/
directory will always be located inside the directory specified in RewriteBase.
[edit]
. . . however, it will not always be the physical path where this .htaccess file exists.
[/edit]
I'd be happy to hear alternative suggestions, as well. Thanks, everyone!