简体   繁体   English

找到 404 的错误页面

[英]finding the error page for 404

We are redirecting 404 error pages to a php page to track.我们正在将 404 错误页面重定向到一个 php 页面以进行跟踪。 We had used .htaccess code:我们使用了.htaccess代码:

ErrorDocument 404 404.php?sr=%{REQUEST_URI}

but when on our 404.php page we are trying to fetch:但是当在我们的404.php页面上时,我们试图获取:

$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?它没有向我们显示用户被重定向的页面名称,如abc.html ,我们想检测该页面名称,任何人都可以帮助解决这个问题吗?

You can use mod-rewrite to redirect a non-existent request to 404.php :您可以使用 mod-rewrite 将不存在的请求重定向到 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. -d匹配现有目录, -f匹配服务器上的现有文件。 RewriteCond checks to see that the requested filename is not ! RewriteCond 检查以查看请求的文件名不是! an existing directory or file before it redirects the request to /404.php.将请求重定向到 /404.php 之前的现有目录或文件。 You can also replace $1 with %{REQUEST_URI} to get the full uri.您还可以将$1替换$1 %{REQUEST_URI}以获得完整的 uri。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM