You can reduce the "cost" of hits to non-existent resources by blocking them from the main httpd.conf (or an applicable included configuration snippet).
Static Redirect
and/or RedirectMatch
directives should be computationally be cheaper than using dynamic mod_rewrite rules especially compared to those loaded from a .htaccess
file. (Although I don't have hard numbers this reference suggests so.)
As already suggested the HTTP return code of 410
gone
would be the most suitable one. Alternatively sending the 404 - file not found
status code would also be suitable and using the Redirect
directive then prevents the web server from having to check the file system for a non-existent resource, reducing load.
For example:
<VirtualHost *80>
ServerName example.com
ServerAlias www.example.com
# All RSS feeds under /rss/legacy/* are gone
Redirect gone "/rss/legacy"
# /rss/[alpha.rss, bravo.rss, ... sierra.rss] are gone,
# but /rss/tango.rss still exists
RedirectMatch gone "/rss/[a-s].*\.rss$"
# /rss/victor.rss has also been discontinued
Redirect 410 "/rss/victor.rss"
...
</VirtualHost>
To further reduce the load and bandwidth of content that no longer exists, you might want to ensure that you don't have a friendly (custom) error document that gets sent when your server returns a status "410 - gone". i.e. Check that your configuration does not include a ErrorDocument 410
setting up a custom error page but is either not set or rather ErrorDocument 410 default
or ErrorDocument 410 "Gone"