添加' /'使网站崩溃

时间:2015-02-06 09:24:18

标签: php jquery html web pdo

这是没有'/'(localhost / index.php)的样子:http://postimg.org/image/jxg239qzn/

在url(localhost / index.php /)的末尾添加它之后: http://postimg.org/image/e01pe0isv/

任何有经验的人都可以就可能的原因给出一个简短的提示。

这是index.php:

require_once("php/config.php");
if(substr_count($_SERVER['PHP_SELF'],'/')==1){ // fixing that bug  
    require_once( ROOT_PATH . "php/header.php" );   
    if(isvalid(quizzid()) == true){
        switch(quizzid()){
            case 0:
                require_once( ROOT_PATH . "php/questionarios.php" );
                break;
            default:
                require_once( ROOT_PATH . "php/questionario.php" ); 
                break;
         } 
     }          
     require_once(ROOT_PATH . "php/footer.php");    // footer
}else{ // if there are more than 1 '/' it would redirect to > index
    header('Location: /index.php');
}

4 个答案:

答案 0 :(得分:0)

我猜服务器假设" index.php"是一个目录,并寻找一个索引文件,路径为" localhost / index.php / index.php"。您是否测试过这是否可能是问题?

答案 1 :(得分:0)

添加/后,include路径从localhost更改为localhost / index.php /并在localhost / index.php / php / config.php位置搜索不存在的config.php。

因此,在添加/后,您的ROOT_PATH未设置。

包括config

时使用绝对路径(完整路径)

require_once( “/ PHP / config.php中”);

答案 2 :(得分:0)

屏幕截图显示,当您在网址末尾添加尾部斜杠时,您的网站无法加载外部文件(CSS,JS,图片)。

最可能的原因是因为您使用外部文件的相对路径。

<link rel="stylesheet" type="text/css" href="style.css">

您的浏览器会尝试加载http://localhost/index.php/style.css而不是http://localhost/style.css


使用外部文件的绝对路径可以解决问题。

<link rel="stylesheet" type="text/css" href="/style.css">

您还可以在HTML中使用<base> element,它将配置从特定目录中提取的所有相对路径:这将影响所有CSS / JS /图像文件,因此它比将所有相对路径更改为绝对路径。

<base href="http://localhost/">

我还建议在Apache's configuration中将AcceptPathInfo设置为Off。这会向http://localhost/index.php/请求获得404 Not Found响应。

答案 3 :(得分:0)

我刚刚意识到问题出在哪里,对我这个bug的愚蠢感到羞耻。

我过去常常包含img,css,js或其他任何东西,我用这种方式:

(之前)链接rel =&#34;样式表&#34;类型=&#34;文本/ CSS&#34; HREF = <强>&#34; CSS / css.css&#34;

(之后)link rel =&#34; stylesheet&#34;类型=&#34;文本/ CSS&#34; HREF = <强>&#34; /css/css.css"

以下是一个很好的答案:relative path to CSS file

谢天谢地,如果对我的愚蠢感到恼火,我感到很抱歉。

(我想在每个答案上加上+1,但我需要15个声望。)