Basj
Basj

Reputation: 46227

Usage of both "Order Deny,Allow" and "RewriteRule"

I have read Deny from all in subdirectory htaccess not overriding file rules in root htaccess and htaccess "order" Deny, Allow, Deny but I don't see why this does not work:

Order Deny,Allow
<Files articles/*.*>
Deny from all
</Files>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

The file example.com/articles/test.txt is still viewable, whereas it should not. This shows that the articles/*.* rule does not work.

Where is the problem in my .htaccess?


Note: Since I have Apache 2.4, I have tried:

<Files "articles/*.*">
Require all denied
</Files>

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]

but the problem is still there.

Upvotes: 0

Views: 694

Answers (1)

Pandurang
Pandurang

Reputation: 1741

Try with below rewrite rule.

RewriteRule articles/.*$ - [F]

This uses the F|forbidden flag.

Note:

When using [F], an [L] is implied - that is, the response is returned immediately, and no further rules are evaluated.

Upvotes: 1

Related Questions