Tracking of 404 pages?

Good day, Habr!


There is a problem. Written in htaccess redirect with 404 error.
An ErrorDocument 404 /errors/404/


and everything looks good, everything works. But there is a need to identify and log pages which the user was thrown to the error page. And here arose plugging. Apache redirect when losing the address in the address bar to redirect. Ie cannot identify the page which was driven into the browser/link. No HTTP_REFERER or in REDIRECT_URL, it is not. It may be possible to set up a redirect so that came again and address, albeit in the form of GET parameter. Anything
October 3rd 19 at 04:19
4 answers
October 3rd 19 at 04:21
And it seemed to me it is not done...
The Url should not change, should change the response from the server, its a custom page with isfinally or something.
Yes I in General not against, but don't know how to write the rewriterule so that it is triggered on a 404 error - wallace64 commented on October 3rd 19 at 04:24
Yes, you wrote everything correctly, but it doesn't redirect to the browser. All global variables are kept the same.

in the /htaccess
An ErrorDocument 404 /404.php

in 404.php
not found - Hiram_Reichert67 commented on October 3rd 19 at 04:27
October 3rd 19 at 04:23
.htaccess:
An ErrorDocument 404 /404.php


404.php:
<?php

header('Content-Type: text/plain; charset="UTF-8');
print_r($_SERVER);
</property-->
<br / > <br / > request: <a href="http://localhost/test/dshgsdgsdhbshjdfh">localhost/test/dshgsdgsdhbshjdfh</a><br> output:<br> the <pre><code>Array ( [REDIRECT_REQUEST_METHOD] => GET [REDIRECT_STATUS] => 404 .... [HTTP_REFERER] => http://localhost/test.html [REDIRECT_URL] => /test/dshgsdgsdhbshjdfh [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /test/dshgsdgsdhbshjdfh [SCRIPT_NAME] => /404.php [PHP_SELF] => /404.php [REQUEST_TIME_FLOAT] => 1375894390.798 [REQUEST_TIME] => 1375894390 [argv] => Array ( ) [argc] => 0 )</code></pre><br> <br / > As you can see, referrer and path, which is not found there. Or I did not understand you?
e-my... repeat. In the array $_SERVER, which comes to the page in $_SERVER['REQUEST_URI'] emblazoned /errors/404/index.php? although in the address bar I typed mysite.ru/123 Perhaps the problem is somewhere in Apache, maybe there are thoughts where to look? - wallace64 commented on October 3rd 19 at 04:26
October 3rd 19 at 04:25
found the root of the problem, but don't know how to solve it. As it turned out the server is apache+nginx, nginx catches first, respectively the management sees the 404 issues a 301 redirect, then Apache picks up the control and shows the page but when redirect to lost original data of the array $_SERVER. Can someone tell me how to solve this problem?
If you have nginx stands as a proxy for Apache, try adding something like this configuration:
proxy_set_header Referer $http_referer
proxy_set_header request_uri $request_uri; - wallace64 commented on October 3rd 19 at 04:28
Maybe we should throw out Apache?
Why is it if You have nginx?

type a bunch of nginx — php-fpm works fine and reliable. - Hiram_Reichert67 commented on October 3rd 19 at 04:31
October 3rd 19 at 04:27
del.the problem was solved without me
sometimes Apache creates $_SERVER['REDIRECT_QUERY_STRING'] - wallace64 commented on October 3rd 19 at 04:30

Find more questions by tags htaccessApachePHP