404 自定义错误页面重定向不显示丢失的文件 URL
我的网站上有一个自定义 404 错误页面,但在网站上执行其他操作时,该错误页面很难找出我丢失的文件问题是什么,因为它重定向到给定的 html 或 php 文件并采用以下 URL将丢失的文件移出地址栏,并将其替换为自定义错误页面的 URL。
例如,当用户登录该网站时,当他们点击提交时,我将其链接到一个 php 文件,但随后浏览器将他们直接带到 404 错误页面,所以我看不出问题实际上是链接到比应有的更高一级的目录。
我尝试使用 php 将丢失文件的 URL 打印到页面,但服务器只获取 404 错误页面的 URL,而不是原始丢失文件的 URL。这是我尝试这样做的方法: http://members.cox.net/midian/tutorials /php404.htm
如何在地址栏中保留原始丢失的 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.
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.
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
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的错误页面重定向到 PHP 驱动的 404 页面,那么变量
$_SERVER["HTTP_REFERER"]
应该包含一些有趣的内容。话虽如此,重定向到错误 404 页面是一个不好的做法。它让搜索引擎和人类访问者都感到困惑。编辑
这里是一个适用于 Apache 的解决方案。将此行添加到您的
.htaccess
文件中:在网站的根目录中创建一个名为
error-404.php
的文件,其中包含以下内容: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.Edit
Here is a solution that works on Apache. Add this line to your
.htaccess
file:Create a file called
error-404.php
in the root directory of your website with the following content:Salman A 发布的内容对我有用。
只有当我在 .htaccess 文件中使用相对路径时,它才起作用:
并且不
ErrorDocument 404 http://www.mydomain.com/error-404.php
第二个版本是在地址栏和页面正文中给我重定向的网址。
另外,您不需要为 404 消息使用 php 页面;如果您不想在页面正文中回显 URL,则 html 页面也可以。
What Salman A posted works for me.
It only worked though when I used a relative path in the .htaccess file:
and not
ErrorDocument 404 http://www.mydomain.com/error-404.php
The second version was giving me the redirected url in the address bar and in the page body.
Also, you don't need to use a php page for your 404 message; an html page works as well if you don't want to echo the URL in the body of the page.