httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jack Bates <>
Subject [users@httpd] RewriteRule in neither "foo/.htaccess" nor ".htaccess" can match
Date Tue, 24 Nov 2009 20:49:33 GMT
I'm struggling a bit with this mod_rewrite rule,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule . %{REQUEST_FILENAME}.html

My goal is, when someone requests, to respond
with "foo.html", if it exists

I originally tried doing this with MultiViews, but MultiViews won't
respond with "foo.html" if "foo" exists, and I have a case where I want,

* to respond with "foo.html",
* to respond with "foo/index.html",
* to respond with "foo/bar.html"

I originally posted about how to do this with MultiViews here,

Aside from patching mod_negotiation, I think my only option is to use

This %{REQUEST_FILENAME}.html rule is inferior to MultiViews because it
doesn't consider the Accept: request header - but it's good enough for
my case

My first struggle was with DirectorySlash - in server context, this
%{REQUEST_FILENAME}.html rule works, even with mod_dir enabled - but
in .htaccess context, mod_dir redirects requests for to before the
rule can respond with "foo.html" instead

I set "DirectorySlash Off" to get around this

My second and current struggle is that in one case, the directory "foo"
already contains a .htaccess with,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

This rule works, before and after I added the %{REQUEST_FILENAME}.html
rule and "DirectorySlash Off" to a .htaccess in the parent directory -
but the %{REQUEST_FILENAME}.html rule doesn't work in this case -
requests for don't respond with "foo.html" :

I found that if I comment all the "Rewrite" statements out of
"foo/.htaccess", then the %{REQUEST_FILENAME}.html rule works again - I
guess any "Rewrite" directive in a .htaccess disables rules in .htaccess
files in parent directories?

So I tried copying the %{REQUEST_FILENAME}.html rule to "foo/.htaccess",
but this still doesn't work - I think "RewriteRule ^$ ..." in
"foo/.htaccess" matches, but doesn't match

So it seems there's no way for a mod_rewrite rule in .htaccess context
to match - with "RewriteRule .
%{REQUEST_FILENAME}.html" in the parent directory, and "RewriteRule ^$
%{REQUEST_FILENAME}.html" in "foo/.htaccess", the rule in
"foo/.htaccess" disables the rule in the parent directory, without
possibly matching

Can we please have on or the other? : )

Either rules in "foo/.htaccess" can match or
rules in the parent directory can match -
currently it seems neither is true : (

I checked that this is still the case with trunk revision 883548

I used this httpd.conf,

- and these .htaccess files,

I didn't have any more success by adding "RewriteOptions inherit"

The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message