Ben Muircroft Ben Muircroft - 5 months ago 23
Apache Configuration Question

.htaccess redirect 404 but remember the mistake as an url variable

My .htaccess file is one line

ErrorDocument 404{HTTP_REFERER}

if I go to (a non-existent page)

It literally takes me to:{HTTP_REFERER}

whereas it should take me to:

why is
being treated as a string?

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^*
RewriteRule .*{HTTP_REFERER}

tried that the HTTP_REFERER is blank

Answer Source

%{HTTP_REFERER} is mod_rewrite variable that cannot be used in ErrorDocument.

You will have to use a mod_rewrite rule instead of ErrorDocument if you want to pass %{HTTP_REFERER}.

Another alternative is to not use %{HTTP_REFERER} at all and use slightly different ErrorDocument directive as this:

ErrorDocument 404 /folder/404.php

and get the original 404 causing URI using:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download