Q:

Browser language based 404 pages with mod_rewrite how to

I am trying to generate language dependant 404 (also other errors) pages purely based on Apache mod_rewrite rules by evaluating the clients HTTP Accept-Language header. I've managed to show the correct pages (english default) with this rules:
RewriteEngine on
RewriteBase / 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule (.+) /esp/error404.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.+) /eng/error404.php [L]

My problem is that I would like to maintain 404 errors and I understand redirect does not allow this type of flag. I am in any case not 100% sure if it's really worth SEO wise as it might be better not to have 404s at all, but I thought that it would be more logical and maintain logs consistent, etc, but I simply can't figure how to achieve that via apache and HTTP:Accept-Language.
Any comments would be mostly appreciated. 

A:

You could use Apache's default error handler to do this.
It should be possible to define an ErrorDocument like so:
ErrorDocument 404 /parseme.php

and then do a language-dependent redirect for requests to /parseme.php like so:
RewriteCond %{REQUEST_FILENAME} ^/parseme\.php$
RewriteCond %{HTTP:Accept-Language} ^es [NC]
RewriteRule (.+) /esp/error404.php [L]

RewriteCond %{REQUEST_FILENAME} ^/parseme\.php$
RewriteCond %{HTTP:Accept-Language} ^eng [NC]
RewriteRule (.+) /eng/error404.php [L]

I have never tried this but this should give you a 404 header, and the error page in the correct language, too.

