Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On our site, we tend to remove pages a lot where the content has expired, and we want to return http status 410 rather than 404 for requests to pages (physical files) that don't exist on our server (the entire site is made up of static files).

We have tried

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ - [G,L]

from this blog post but that just breaks our entire site, serving a 410 for every request.

We are using Apache 2.2.3

share|improve this question
    Redirect gone /path/to/resource

Is the correct way to do it. If that's causing errors for you, make sure you have mod_alias loaded in the server.

share|improve this answer

I believe chris's answer is pretty good. If you don't want to use PHP script it could become:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$                - [G,L]

Don't forget that the mod_rewrite page also has a compainion mod_rewrite wiki.

share|improve this answer

Create an errorpage.php (or whatever scripting language) and have that file return a http status header of: 410 Gone, and add the following to your apache configuration, which basically says if the requested url is not a file nor a directory (ie file doesn't exist), then load the errorpage.php document.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /errorpage.php [L]

The errorpage.php could be something as simple as:

<?php header($_SERVER['SERVER_PROTOCOL'].' 410 Gone');

You could also have that errorpage.php contain a list of (or other means of tracking) deleted pages, so that it could properly return 404 or 410 http status depending on whether the resource had previously existed or not.

share|improve this answer

Your Answer


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.