Missing Files


The general idea here is that you want to redirect visitors if a particular file is missing; however it is considered better to simply state the requested URI is missing and issue a 404 Not Found. Some site developers may choose not to do this and this method will provide an alternative and a variety of choices.

Issue a non-404

In this example, example.com should, of course, be replaced with your own website address. We want to issue a clean web page to outsiders and those with an empty referer but sill allow internal people to get the standard 404 Not Found error message.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !example\.com [NC]
RewriteRule ^ /UnderConstruction.html [L]

Replace the Missing File with Another File

If you want the missing file to be replaced with a URL from another site, you can do so by providing a full URL (http//:some.other.server/) in that RewriteRule:

RewriteEngine on
RewriteRule ^ http://other.example.com/ [R=302,L]

This is the same as

# this issues a 302 redirect, not a 404 not found status code
ErrorDocument 404 http://other.example.com/



Issuing a non-404 (file found but not the one requested) is a way to cleanly fail if site content if missing. However this can confuse and polute the web crawlers indexing your site.

Issuing a Redirect-If-Missing is another approach however this too can lead to later confusion about which resource is valid if not up-to-date.

Bottom-line: Choose a particular error eporting and handling policy and stick with it.

  • No labels