404自定义错误页面重定向不显示缺少的文件URL [英] 404 custom error page redirect doesn't show missing file URL

查看:145
本文介绍了404自定义错误页面重定向不显示缺少的文件URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个自定义的404错误页面,但是在该网站上执行其他操作时,由于错误页面重定向到给定的html或php文件并采用从地址栏中删除丢失文件的URL,并将其替换为自定义错误页面的URL.

I have a custom 404 error page on my site, but while doing other things on the site, the error page makes it hard to figure out what my missing file problems are because it redirects to a given html or php file and takes the URL of the missing file out of the address bar and replaces it with the URL of the custom error page.

例如,当用户登录该站点时,当他们单击提交"时,我将其链接到php文件,但是随后浏览器将其直接带到404错误页面,所以我看不到问题所在实际上是指向一个目录的链接.

So for example, when users log in to the site, I have it link to a php file when they hit submit, but then the browsers takes them straight to the 404 error page, so I can't see that the problem is actually a link to one directory higher than it should be.

我尝试使用php将丢失的文件的URL打印到页面,但是服务器只是获取404错误页面的URL,而不是原始的丢失的文件URL.这是我尝试执行的操作: http://members.cox.net/midian/tutorials /php404.htm

I've tried printing the URL of the missing file to the page using php, but the server just grabs the URL of the 404 error page, rather than the original missing file URL. Here is how I tried doing that: http://members.cox.net/midian/tutorials/php404.htm

如何在将原始缺少的URL保留在地址栏中的同时显示自定义错误页面,或者将缺少的文件的URL打印到页面上?

How can I either show the custom error page while keeping the original missing URL in the address bar, or print out the URL of the missing file to the page?

推荐答案

如果将错误页面重定向到PHP支持的404页面,则变量$_SERVER["HTTP_REFERER"]应该包含一些有趣的内容.话虽如此,重定向到错误404页面是一种不好的做法.它使搜索引擎和人类访客都感到困惑.

If your error pages are redirected to a PHP powered 404 page then the variable $_SERVER["HTTP_REFERER"] should contain something interesting. Having said that, redirecting to a error-404 page is a bad practice. It confuses search engines and human visitors alike.

这是在Apache上运行的解决方案.将此行添加到您的.htaccess文件中:

Here is a solution that works on Apache. Add this line to your .htaccess file:

ErrorDocument 404 /error-404.php

在网站的根目录中创建一个名为error-404.php的文件,其内容如下:

Create a file called error-404.php in the root directory of your website with the following content:

<?php
echo "<h1>404 Not Found</h1>";
echo "<p>The page {$_SERVER['REQUEST_URI']} was not found on this server</p>";

这篇关于404自定义错误页面重定向不显示缺少的文件URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆