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

    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.


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.


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.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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