We are redirecting 404 error pages to a php page to track. We had used .htaccess
code:
ErrorDocument 404 404.php?sr=%{REQUEST_URI}
but when on our 404.php
page we are trying to fetch:
$requri = getenv ("REQUEST_URI");
It is not showing us the pagename from which user got redirected like abc.html
and we want to detect that page name, can anyone help in this matter?
You can use mod-rewrite to redirect a non-existent request to 404.php :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /404.php?sr=$1 [NC,L]
-d matches an existing directory and -f matches an existing file on the server. RewriteCond checks to see that the requested filename is not ! an existing directory or file before it redirects the request to /404.php. You can also replace $1
with %{REQUEST_URI}
to get the full uri.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.