htaccess - Make a RewriteCond gobal

Is it possible to make 1 or more RewriteCond gobal in htaccess to avoid repeating

RewriteCond %{REQUEST_METHOD}  !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

at the beginning of every RewriteRule?

Answers


Yes repetition can be avoided by having your conditions like this:

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

Which means skip rest of the rules if any of these conditions are met:

  1. If request is for POST method OR
  2. If request is for a valid file OR
  3. If request is for a valid directory

PS: Make sure to place this rule on top of other rules you want to skip.


Need Your Help

Prerender.io: everything is cached, but facebook can't get correct info for front-page

angularjs share prerender

I have a weird anomaly. While my content pages work fine with facebook sharing (http://example.com/31) , my first page however (http://example.com/), for some reason, gets invalid data when doing f...

Behavior of ufuncs and mathematical operators differ for subclassed MaskedArray

python numpy

I am attempting to subclass numpy.ma.MaskedArray, but keep running into an issue where directly using mathematical operators on my subclass behaves differently than directly using the analogous ufu...