Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No-op Apache mod_rewrite rule

I have an .htaccess file like this:

RewriteCond /question2answer/%{REQUEST_FILENAME} !-f
RewriteCond /question2answer/%{REQUEST_FILENAME} !-d
RewriteCond OTHER_CONDITION_1
RewriteRule RULE_1 [L]

RewriteCond /question2answer/%{REQUEST_FILENAME} !-f
RewriteCond /question2answer/%{REQUEST_FILENAME} !-d
RewriteCond OTHER_CONDITION_2
RewriteRule RULE_2 [L]

...

De Morgan's laws tells me there is a better way to do this:

RewriteCond /question2answer/%{REQUEST_FILENAME} -f
RewriteRule NO-OP [L]
RewriteCond /question2answer/%{REQUEST_FILENAME} -d
RewriteRule NO-OP [L]

RewriteCond OTHER_CONDITION_1
RewriteRule RULE_1 [L]

RewriteCond OTHER_CONDITION_2
RewriteRule RULE_2 [L]    

...

What is the no-op rule that I can use here? And if there are many, I am seeing the one with the least performance impact.

like image 747
William Entriken Avatar asked Feb 27 '15 15:02

William Entriken


1 Answers

NO_OP (no operation) rule can be this:

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

Which means if request is for a file OR if request is for a directory then don't do anything (denoted by - in target URI).

like image 120
anubhava Avatar answered Oct 02 '22 19:10

anubhava