Creating Exceptions to Apache Redirect Directives

When I need to temporarily (or permanently) take down a bunch of resources from my Apache webserver, I usually put the following in a .htaccess file in the appropriate directory:

Redirect gone /directory/not/to/serve/

However, sometimes I’d actually like to continue serving a specific document somewhere within the redirected direcotry, but only that specific file. So I searched high and low for a way to tell Apache “respond to all requests for any files in /directory/not/to/serve with a 410 Gone header except for this specific file” but came up empty.

The (hugely laborious) workaround is, of course, to specify each file—as opposed to part of a directory path—not to serve like this:

Redirect gone /directory/not/to/serve/index.html
Redirect gone /directory/not/to/serve/bad_file.html
...
Redirect gone /directory/not/to/serve/sub/icky_file.html

and, unfortunately, wildcards (*, ?, etc.) aren’t allowed in Redirect directives.

Of course, as is usually the case, a simple Unix command solves all the above problems:

ln -s file_I_want_to_serve.html /directory/to/serve/file_I_want_to_serve.html

worked like a charm. That is to say, a symbolic link to the file_I_want_to_serve.html created in a directory outside the Redirected directory lets Apache access the file and serve it, despite its true location. You can use hard links or symlinks for this, and you can even link whole directories and access their contents via the link, too. Very useful.

I have to learn to keep it simple and stop looking for complex solutions all the time.