What I basically want to do is redirect any 404 requests to /404/ but then I would like to have it ‘pull’ the page to index.php?error=404, whilst leaving the URL as /404/ – then I can get the referer using PHP (using $_SERVER[‘HTTP_REFERER’]`).
I believe that the ReWrite rules should go prior to the ErrorDocuments, so my .htaccess file looks like the following:
RewriteRule ^404/$ /index.php?error=404
ErrorDocument 404 /404/
I know that I’m probably doing something fundermentally wrong with the above, since the 404 page/$_SERVER gets no referer URL (probably because of ErrorDocument).
The index.php page gets all the content routed through it (something very standard, I gather) and sends performs a header redirect to /404/ if/when a page/file is not found. Though if someone were to enter the URL into the browser incorrectly, I would like to get the original request, though since the page is being redirected anyway, should that be still be the referer in PHP?
I suggest you do it differently by directly using a
error.phpfile:You can then use that file as a proxy injecting all needed information into
index.php. If you need to find out the apache status code (and additional useful information), take a look into the$_SERVERsuperglobal array.Doing it this way gives you a better level of control and you can deal with server-differences easier in case you need to migrate your application from one server to another.