在 PHP 404 标头返回“哎呀!此链接似乎已损坏."

长话短说,我在网站上有显示评论的动态页面.如果没有与特定城市/县/地区/等相关的评论,则 mysql 查询返回 0 行,触发以下代码:

To make a long story short, I have dynamic pages on a website that display reviews. If there are no reviews associated with a particular city/county/area/etc the mysql query returns 0 rows which triggers the following code:

if (!$validRevQuery) {
    header("HTTP/1.0 404 Not Found");
    include("http://{$PDS['site']}/404.php?request=".urlencode($_SERVER['REQUEST_URI']));
    exit;
}

在某些网络主机上,这会触发URL 文件访问被禁用"错误.这很好,但是在允许 URL 文件访问的那些上,404 文件被包含并正确显示.我稍微更改了代码以显示绝对路径,如下所示:

On some webhosts this triggers a "URL file-access is disabled" error. Which is fine, but on the ones that allow URL file-access, the 404 file is included and properly displayed. I changed the code slightly to display an absolute path like so:

if (!$validRevQuery) {
    header("HTTP/1.0 404 Not Found");
    $_GET['request'] = urlencode($_SERVER['REQUEST_URI']);
    include($_SERVER['DOCUMENT_ROOT']."/404.php");
    exit;
}

现在,它给了我通用的糟糕!此链接似乎已损坏".错误页面.(我有谷歌工具栏,所以这可能因浏览器和插件而异).不知道为什么会发生这种情况,因此感谢您的帮助!

And now, it's giving me the generic "Oops! This link appears to be broken." error page. (I have google toolbar, so this may be different depending upon browser and plugins). No idea why this is happening, so any help is appreciated!

推荐答案

你的问题与你包含的内容无关:是你的页面太小了.

Your problem has nothing to do with what you include: It's that your page is too small.

根据我的经验,Chrome 的内置糟糕"页面会显示,就像 Internet Explorer 中的页面一样,当页面仅发出 404 标头并且内容的字节数少于定义的字节数时(我认为它是 512 字节)IE,不知道 Chrome 的限制).

In my experience, Chrome's built-in "Oops" page is displayed, like the one in Internet Explorer, when the page emits only the 404 header and less than a defined number of bytes of content (I think it's 512 bytes in IE, don't know the limit in Chrome).

我倾向于在我的 404 页面中填充数百字节的 HTML 注释中的无意义内容,以确保显示自定义 404 页面.

I tend to pad my 404 pages with a few hundred bytes of meaningless content wrapped in HTML comments to make sure the custom 404 page is displayed.

或者当然,利用这个机会来一些很酷的 ASCII 艺术

Or of course, use the opportunity for some cool ASCII Art!

   <!--                            oooo   ooo
                                   $   $  $   $
                                   "o  $ $  o""
                                     o  "   "ooooo
                                 oo ""           o$
                   o            o            oo  "
                  $$             $o$""$o  ooo$
                  $"$          o $    "$  $
        o$o       $ "$         $ $     $ $
         $$$o     $$ "$       o$ $     o $o
         "$ ""o   "$   "o     $$ "o     o"
     $o   $$   "o  $     "oo  $"  $   o$"
      "$   $o    "o$$       "o$    $o$" oo$
        "o "$o                     "$o $"$$
          "        oo$$$$$$$oo        $oo$$""      o" o
 """""""""      o$$$$$$$$$$$"$o             o"""$o$$  o$
       ooo$$$"o$$$$$$$$$$$$$$ "$o    o   o$$$o   $ $ o$
    o$$$$$$$$$$$$$$$$$$$$$$$$    "oo  o      ""o  "$ $
   $$$$$$$$$$$$$$$$$$$$$$$$$$      "$o   o$$"""$     " oo""o
o""""$$$$$$$$$$$$$$$$$$$$$$"         ""$o"$o          "   o$
     "$$$$$$$$""""$""$$$""              "$oo$""$o     o$"""
      $$$$$$$"                           $""""$"  o""""
       $"""""$ooooo        ooooo$$$$$$$     o$" o"
        $     """" oooo$$$$$$$$$$$$$$"     $"  o"
      oo$   oooo$$$$$$$$$$$"""""$$$$"    o$" o$"
    "$ $o$$$$$$$$$$$$$""$     o$$$"oooo$"  o"
      "o$ "$$$$$$$$$$$$         $$o$"$$$   $"
        "$  ""$$$$$$$$$        o$"$$$ "$$o$$
          "o   ""$$$$$$o     o$$$$ ""$o """$
            "$o    ""$$$$$$o"  o$$$$oo o$$$$
               ""$oo     $$" "$$$"" ooooooo$
                    """"$"  o$"   oo$$$$$""$$
                       $ oo$"  o$$$$$""  ooo$
                       $o$"  o$$$$"  oo$$$$$$$o
                        $$ o$$$"  o$$$$$$"""""$o
                         "o$$"  o$$$$""  o$$$$$$$o
                           "$oo$$$$"  o$$$$$""" o$o
                             "$$$" oo$$$"" oo$$$$$$$
                          ooooo$oo$$$"" oo$$$$"""$$""
                         $"oooo $$$" o$$$$""      $
                       o$"o$   $$"oo$$""       " o$
                       $ o$$o  $$o$$"          oo$$
                       $ $$$$  $$$$$$$$$$$$$$$$$$$$
                       $ $$$$  $$$$$$$$$$$$$$$$$$$$"
                       $ $$$$  $$$$$$$$$$$$$$$$$$$$
                       $ ""    ""$$$$$$$$$"""$""""
                       $o         $"$"    " $"
                        $o       $$  $o    o$
                         "$o   o$$    ""$$$"
                           """"""  -->

相关文章