Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

I think this is what you want: Emulating ErrorDocuments with Mod_Rewrite

share|improve this answer
add comment

Use a different HTTP status code instead?

Say, 403 (Forbidden) - what does it matter what the (malicious) client sees?

share|improve this answer
    
because I use Google webmaster tools to monitor broken pages on my website and I would like missing files to be flagged as 404 and not 403. –  user64204 Mar 20 '12 at 11:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.