Pekka
Pekka

Reputation: 449475

How to simulate [L] in .htaccess

I have a .htaccess file with a number of RewriteRules.

How can I exclude already existing files and directories from having run through each of the RewriteCond / RewriteRule pairs?

This:

RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .*  - [F,L]  

won't work reliably because according to this SO question:

within the .htaccess context, [L] will not force mod_rewrite to stop. it will continue to trigger internal sub-requests:

How can I make this work? Alternatively, is ther a control structure like if condition applies, go through this block of rules, otherwise skip and go to end in mod_rewrite?

Upvotes: 2

Views: 1231

Answers (1)

Gumbo
Gumbo

Reputation: 655289

The problem with your rule is that both conditions can not be fulfilled at the same time because a regular file (-f) cannot also be a directory (-d). Try this instead:

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

Upvotes: 1

Related Questions