【问题标题】:Redirect wrong directory (status code is 200 NOT 404)重定向错误的目录(状态码是 200 NOT 404)
【发布时间】:2018-06-28 17:36:19
【问题描述】:

我在重定向不存在的目录(或者可能是 php 包含)时遇到问题。

例子:

  • 正确路径:

    olafernst.com/shooting.php = 很好

  • php 中的错字:

olafernst.com/xxshooting.php = 很好 (404 redirect)

  • php 中的错字和不存在的目录:

olafernst.com/xxshooting.php/nonexistfolder = 很好 (404 redirect)

  • 路径正确但目录不存在:

olafernst.com/shooting.php/nonexistfolder = 返回: 状态码200 insted of 404 找不到包含的php。

有什么想法吗?

谢谢


<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<html lang="en-EN">
    <head>

        <meta charset="utf-8">
        <title>Olaf Ernst Photography</title>
        <meta name="description" content="Olaf Ernst captures beautiful nature and stunning portraits with decades of experience. Visit to see for yourself. Landscapes, Portraits, Cities, Urban, Nudes.">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="copyright" content="Olaf Ernst Photography">
        <meta name="msvalidate.01" content="8FC8C224898F3874EAA240BA4B1E6133" />
        <link rel="shortcut icon" href="favicon.ico">

        <!-- plugins' css -->
        <link rel="stylesheet" href="css/plugins.css">

        <!-- google fonts -->
        <link href='https://fonts.googleapis.com/css?family=Oswald:400,700,300%7cPoppins:400,300,500,700,600' rel='stylesheet' type='text/css'>
        <!-- main css file -->
        <link rel="stylesheet" href="css/main.css">

        <!-- modernizr -->
        <script src="js/lib/modernizr-2.6.2.min.js"></script>



    </head>

    <body>





    </body>
</html>

【问题讨论】:

  • 如何收录?你能分享你的代码吗?
  • 像这样:
  • 我仍然没有看到任何代码,也不明白你是如何做到这一点的:“olafernst.com/shooting.php/nonexistfolder”
  • 也许我不想正确描述这个问题。如果您在浏览器中输入了错误的 URL,菜单将无法正确显示。我预计不存在的目录会出现 404 错误。我检查了返回状态,它是 200 而不是 404。所有重定向都按预期工作。只有目录名称错误的那些不起作用。你要我分享什么代码?
  • 你使用一些 .htaccess 规则吗?您如何将脚本名称从 url 翻译为包含?你可能使用 $_SERVER["PHP_SELF"] 吗?

标签: php .htaccess redirect http-status-code-404


【解决方案1】:

其实,看看你的真实现场,我想我了解情况,可以给你一些建议和解释。

当您在 URL 中输入有效的 .php 时,例如shooting.php/nonexistfolder,.php 之后的部分将被视为查询字符串(即使无效)并且网站会加载。文件下不能有子目录(例如,shooting.php)。如果您想使用查询参数,它们的格式正确,如下所示: shooting.php?key=value&anotherkey=secondvalue

如果您想使用友好的 URL,例如 射击/阿姆斯特丹和射击/鹿特丹你需要 .htaccess 文件,规则重写 URL-s 和 mod_rewrite 在 apache 中启用。

【讨论】:

  • 非常感谢。你让我朝着正确的方向前进。我想我可以从这里解决。再次感谢。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2016-02-10
  • 2013-01-09
  • 2012-07-01
  • 2018-09-05
  • 2016-11-30
  • 1970-01-01
  • 2021-11-18
  • 1970-01-01
相关资源
最近更新 更多