How to return 410 with lighttpd

Almad asked:

I have a subdomain with service I am going to kill.

I’d like to use 410 to mark it as such.

Is there a way to do that with lighttpd without resolving to mod_magnet and lua scripts?

My answer:


Set the document root to an otherwise empty directory, and use a dynamic error handler to send a 410 response.

Example:

$HTTP["host"] == "gone.example.com" {
  server.document-root = "/var/www/gone"
  server.error-handler-404 = "/gone.php"
}

Where /var/www/gone/gone.php contains something like the following:

<?php
header("HTTP/1.1 410 Gone");
header("Status: 410 Gone");

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.