Re: RewriteRule in neither "foo/.htaccess" nor ".htaccess" canmatch http://examp

Re: RewriteRule in neither "foo/.htaccess" nor ".htaccess" canmatch http://examp

am 25.11.2009 18:44:38 von ms419

> On 11/24/09, Jack Bates freezone.co.uk> wrote:
> > * /foo/ to deliver /foo/index.html, or whatever it would naturally
> deliver
> > * /foo to deliver /foo.html always
>=20
> IIUC, your problem boils down to:
>=20
> /.htaccess has your desired behavior
> /foo/.htaccess has some undesired, incompatible catch-all behavior

Almost -

/.htaccess has one desired behaviour,
/foo/.htaccess has another, also desired, compatible behaviour

In my case I don't think it would matter which rules took precedence

The trouble is, when there is any "Rewrite" directive in /foo/.htaccess,
I can't get the rules from /.htaccess to apply - either by using
"RewriteOptions inherit" or by copying the rules from /.htaccess
to /foo/.htaccess

Here's a shorter, hopefully clearer example,

Contents of /.htaccess,

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

With this configuration and no "Rewrite" directives in /foo/.htaccess,
requests for http://example.com/.../foo successfully respond
with /foo.html

- but if I make the contents of /foo/.htaccess,

> RewriteEngine On
> RewriteOptions inherit

Now requests for http://example.com/.../foo no longer respond
with /foo.html : (

So the fact that there are "Rewrite" directives in /foo/.htaccess is
interfering with requests for http://example.com/.../foo, but the rules
in /foo/.htaccess can't match requests for http://example.com/.../foo
(although they can match requests for http://example.com/.../foo/)

I think it's currently impossible for *any* rule in /foo/.htaccess to
match http://example.com/.../foo

I think it should be one or the other - either it should be possible for
a rule in /foo/.htaccess to match http://example.com/.../foo, or rules
in /foo/.htaccess shouldn't disable rules in /.htaccess

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Re: RewriteRule in neither "foo/.htaccess" nor".htaccess" can match http://e

am 25.11.2009 20:16:26 von aw

Jack Bates wrote:
....
Hi again.
I am not saying here that you are necessarily wrong, or that there is
not a good justification to what you are trying to do, or to what you
asserted at the end of the previous post.

But one thing you should be aware of, is that when you place
instructions in a .htaccess file, you are in fact asking Apache
to walk down the whole directory tree, applying all its configuration
rules level by level as it does so, until it gets to the level of the
directory where it finds the first .htaccess file.
Then, because this .htaccess rewrites the URL, you are basically telling
Apache to throw away all the result of its previous work, and to start
again at the top with the new URL. Then, in your case and assuming
everything works down to that level, it will end up at the level of the
subdirectory, and find again a .htaccess with rewrite rules. So it will
again rewrite the URL, and again restart at the top.
In the best of cases, that is rather inefficient.
In the less best case, you have missed an intermediate transformation
somewhere, which is leading to a series of rules being applied, that is
different from what you expect.

My personal point of view is that one should avoid .htaccess files if
one can, which is most of the time when one has access and can modify
the main server configuration files, as you seem to be able to.
..htaccess should be reserved for cases where one does not have access to
the server condiguration, and only to one's own directory for instance.

I have not followed your rules step by step, and do not really wish to,
and do not have access to your full configuration sequence of directives
anyway. But given that Apache is being used on hundreds of thousands of
sites, many of them using mod_rewrite and .htaccess files, and
apparently seems to be doing fine most of the time, my current odds
would be in the order of magnitude Apache 10 / Jack 1.

It may be so for instance that what is interpreted the first way around
as the request filename, is no longer considered as such if there is a
subdirectory below the current one. Or some other such apparently
obscure side-effect.

So anyway, if it does not work the way you want when you have a
hierarchical set of rewrite rules in .htaccess files, it may be worth
asking yourself if it is not possible to remove one such level and move
the corresponding rules into the main part of the configuration, which
would probably be more efficient anyway.




------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org