Reputation: 7680
I am trying to do a rewrite for all requests EXCEPT if the URL points to:
So I have the following that should have dealt with it:
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ redirect.php [QSA]
But when I navigate to a folder that contains an index.php
(and yes I have checked that DirectoryIndex
is set to index.php
), it still performs the rewrite.
The funny thing I also found is that if I had a .htaccess
in that folder with RewriteEngine on
(just that), then the rewrite rule above works...
Any pointers?
Upvotes: 6
Views: 3785
Reputation: 143906
You need to check for the directory part:
RewriteCond %{REQUEST_FILENAME}/index\.php !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ redirect.php [QSA,L]
Also:
The funny thing I also found is that if I had a .htaccess in that folder with RewriteEngine on (just that), then the rewrite rule above works...
This is because rewrite rules in subdirectories have precedence over any rules in parent directories. So if you have a subdirectory with RewriteEngine On
, with no rules, then that means that subdirectory has precedence over rewrite rules in the parent directory and there are no rules. (a bit confusing).
Upvotes: 6
Reputation: 785276
Try this rule in your root .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1/index.php !-f
RewriteRule ^(.*?)/?$ redirect.php [L]
Upvotes: 5