I have a Drupal
website which contains the below default mod_rewrite
rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
That means that requests that match an existing file or directory will be served directly instead of triggering the index.php
script.
The problem is that requests to non-existing files do not match the above rules and get redirected to index.php
which bootstrap the entire Drupal
application and unnecessarily load the website.
In order to bypass Drupal
for missing files I have created the following rules:
RewriteCond %{REQUEST_URI} (.jpg|.jpeg|.css|.js|.png)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* - [L,R=404]
This works, but the problem is that the 404
redirects relies on ErrorDocument 404 /index.php
which ends up bootstrapping Drupal
.
I need to keep ErrorDocument 404 /index.php
because Drupal
is used to serve useful 404
pages for dynamic content. I tried to define several ErrorDocument 404
(1 before my rules and 1 before the Drupal rules) but only the last one applies.
Q: How can I serve an empty 404
page for requests to non-existing files without changing the ErrorDocument 404
directive?