I've noticed an issue with [OR] in htaccess that I don't understand. What I want to do is redirect every non-existent file and every file that is a .php file (and not /index.php) to /404/. By my understanding following two blocks should do the same thing:
# .htaccess 1
RewriteEngine on
# cond 1
RewriteCond %{REQUEST_FILENAME} !-f [OR]
# cond 2
RewriteCond %{REQUEST_FILENAME} !index\.php$
# cond 3
RewriteCond %{REQUEST_URI} \.php$
# rule 1
RewriteRule [^\.]*\.[a-zA-Z0-9]+$ /404/ [L]
# rule 2
RewriteRule ^(([^/\.]+)/?)*?$ /index.php [L]
and this:
# .htaccess 2
RewriteEngine on
# cond 1
RewriteCond %{REQUEST_FILENAME} !-f
# rule 1
RewriteRule [^\.]*\.[a-zA-Z0-9]+$ /404/ [L]
# cond 2
RewriteCond %{REQUEST_FILENAME} !index\.php$
# cond 3
RewriteCond %{REQUEST_URI} \.php$
# rule 2
RewriteRule [^\.]*\.[a-zA-Z0-9]+$ /404/ [L]
# rule 3
RewriteRule ^(([^/\.]+)/?)*?$ /index.php [L]
Yet, only the second block does what I want. The first .htaccess, for example - fails to redirect a non-existent file a.pdf and instead displays default server message about file not being found.
Can somebody please explain this to me?