重定向错误的目录(状态码是 200 NOT 404)

Redirect wrong directory (status code is 200 NOT 404)

我对不存在的目录进行重定向(或者 php 包含)时遇到问题。

示例:

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

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

olafernst.com/shooting.php/nonexistfolder = returns: 状态代码 200 代替了 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>

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

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

如果您想使用友好的 URL,例如 shooting/amsterdam 和 shooting/rotterdam 您需要 .htaccess 文件,并在 apache 中启用规则重写 URL-s 和 mod_rewrite。