RewriteRule in neither "foo/.htaccess" nor ".htaccess" can match http://example.com/.../foo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 http://example.com/.../foo, 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,

* http://example.com/.../foo to respond with "foo.html",
* http://example.com/.../foo/ to respond with "foo/index.html",
* http://example.com/.../foo/bar to respond with "foo/bar.html"

I originally posted about how to do this with MultiViews here,
http://thread.gmane.org/gmane.comp.apache.user/87707

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

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
http://example.com/.../foo to http://example.com/.../foo/ 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 http://example.com/.../foo 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 http://example.com/.../foo/, but doesn't match
http://example.com/.../foo

So it seems there's no way for a mod_rewrite rule in .htaccess context
to match http://example.com/.../foo - 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 http://example.com/.../foo

Can we please have on or the other? : )

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

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

I used this httpd.conf,
http://www.sfu.ca/~jdbates/tmp/apache/200911240/httpd.conf

- and these .htaccess files,
http://www.sfu.ca/~jdbates/tmp/apache/200911240/www.tgz

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:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux