php发送404头问题

发布于 2024-12-07 05:58:47 字数 376 浏览 1 评论 0原文

一个简单的问题。我知道如何在 php 中发送 404 标头,但是当我这样做时,页面仍然继续加载内容。在这种情况下,我还必须使用 die() 来终止脚本。我有一个定制的自制 cms,速度非常快并且非常适合我的网站。但由于某种原因,谷歌索引了该网站的不正确链接,这很可能是由于一些不再存在的旧代码造成的。发生的情况是,诸如“/AWebDirectory/AndAnother/function.fopen/”之类的目录已附加到url,即

www.someurl.com/index.php/AWebDirectory/AndAnother/function.fopen/

这不会抛出404,因为index.php存在,但由于目录结构,CSS和内容没有加载。任何帮助表示赞赏。

A quick question. I know how to send a 404 header in php but when I do the page still continues to load content. In this case must I kill the script also with die(). I have a custom home made cms which is very fast and well suited to my site. But for some reason google has indexed an improper link to the site that was most likely due to some old code that no longer exists. What is happening is that directories such as "/AWebDirectory/AndAnother/function.fopen/" has gotten appended to the url i.e.

www.someurl.com/index.php/AWebDirectory/AndAnother/function.fopen/

This is not throwing a 404 as index.php exists but the css and stuff is not loading due to the directory structure. Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单爱 2024-12-14 05:58:47

您需要退出脚本,否则它会继续运行。这是正常的。我不是 100% 确定,但我认为您可能正在寻找重定向:

<?php

/**
 * @see http://php.net/manual/en/function.header.php
 */

header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

尝试使用 404 标头,然后重定向到您的自定义 404 页面。这应该能让你启动并运行。

You need to exit the script or it will just keep going. This is normal. I'm not 100% sure, but I think you might be looking for a redirect:

<?php

/**
 * @see http://php.net/manual/en/function.header.php
 */

header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

Try using both the 404 header, and redirect to your custom 404 page. That should get you up and running.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文