Forum Moderators: phranque

Message Too Old, No Replies

RewirteOptions Inherit not respected?

         

localghost

8:51 am on Oct 4, 2011 (gmt 0)

10+ Year Member



In my root directory i got an .htaccess file containing:
RewriteEngine On
RewriteRule ^dir1(/(.*))?$ suspend.php

I'm trying to redirect each of the request within dir1 to suspend.php.
This worked perfectly until I put .htaccess file within dir1 with the following content:

RewriteOptions Inherit
RewriteRule ^soap/([^/]+)/([^/]+)/?$ index.php?start=soap&method=$1&plugin=$2&%{QUERY_STRING}

If I remove the .htaccess withing dir1 the root .htaccess redirects to suspend.php just fine. Even if comment the RewriteRule in dir1:

RewriteOptions Inherit
#RewriteRule ^soap/([^/]+)/([^/]+)/?$ index.php?start=soap&method=$1&plugin=$2&%{QUERY_STRING}

the redirect to suspend.php does not work.

Can you suggest what do I miss?

Please help :)

lucy24

9:02 pm on Oct 4, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can you start by explaining in English what you're trying to do? In particular, what's supposed to happen in the second htaccess that can't happen in the first one?

I assume you're taken into account Apache's dire warning [httpd.apache.org]:

Rules inherited from the parent scope are applied after rules specified in the child scope.


g1 is going to explain what this means in formal terms. In informal terms it means "I'm not touching this directive with a barge pole". When you have multiple htaccess files*, problems increase exponentially. 2 files, 4 times as many problems. 3 files, 8 times as many.


* With maybe an exception for htaccess files that consist of the single line "Options +Indexes" or equivalent.

localghost

12:39 pm on Oct 5, 2011 (gmt 0)

10+ Year Member



Well, the first .htaccess attempts to restrict access to several subfolders redirecting to suspend.php (in the example I have put only one - dir1). In fact there are lots of subfolders and this is the only reasonable way to restrict access to some of them.

However in each of the subfolders (like that dir1) I got a RewriteRule which should be respected as well. The rule in each of the subfolders attempts to rewrite /soap/ like request to index.php?... as I have stated in my first post. In this case the redirect to suspend.php DOES NOT WORK. In fact even if I remove the RewriteRule in the second htaccess in dir1 and leave only the line with RewirteOptions Inherit the redirect to suspend.php in the parent htaccess DOES NOT WORK either.

Yes, I'm aware of this:
Rules inherited from the parent scope are applied after rules specified in the child scope.

The fact is that the rules from the parent scope are not applied at all. This is my problem.

Does this make it clearer?

lucy24

6:19 am on Oct 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



We're not ignoring you. Inheritance is simply one of those things that people would prefer not to touch with a barge pole. (Except in CSS, where "inherit" generally means "do exactly what you would have done if I hadn't said anything".)

My gut feeling is that even if it seems like more trouble at the outset, it will be safer to put all your rules in the top-level htaccess.

You can always take rules that only apply within one subdirectory and put them further up. The other way around creates a mess. Things in the form

RewriteRule dir1/dir2/dir3/blahblah dir1/dir2/dir3/dir4/blahblah

will work just as well in the root as in dir1, dir2 or dir3. Do as I say. Not as I do. The request will simply hold its metaphorical breath until it reaches /dir3/ And of course if it's something more like

RewriteRule dir1/dir2/dir3/blahblah dir1/blahblah

you may as well get it over with right away instead of sending your request all the way up to /dir3/ ("I've been reassigned to dir1/blahblah? Well, now they tell me.")

I've got a nasty feeling I have just explained why my /paintings/ directory should not have its own htaccess. Oops.