PHP 网站在重命名/添加新页面后无法正常工作

在我的网站上,我有一个index.php带导航栏的。然后,我需要添加另一个名为 的页面second.php,并相应地更新我的导航栏代码(我有一个nav.html导航栏文件,以便我可以使用 JS 将它加载到站点的每个页面上)。我还将导航栏代码添加到second.php. 但是,当我打开时,没有出现index.php指向的链接。second.php

我尝试重新启动我的计算机,重新启动我的 MAMP 服务器,重新打开我的代码编辑器,重新打开浏览器,但没有任何效果。然后,我尝试重命名我的文件(出于测试目的以及因为我需要更好的文件名)并相应地更新文件名的所有实例。但后来出现了:

http://img4.mukewang.com/645dda8f0001b7a501470052.jpg

然后是我的目录中的文件列表。特别是,该网站没有显示。有人可以解释发生了什么以及我该如何解决吗?


nav.html:


<body>

    <header>

        <div class="logo">

            <h1 class="logo-text"><a href="home.php">Welcome!</a></h1>

        </div>

        <i class="fa fa-bars menu-toggle"></i>

        <ul class="nav">

            <li><a href="home.php">Home</a></li>

            <li><a href="about.php">About</a></li>

        </ul>

    </header>

</body>

home.php(以前second.php):


<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie-edge">

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">

    <link rel="stylesheet" href="css/style.css?v=<?php echo time(); ?>">


    <!-- Font Awesome -->

    <link rel="stylesheet" href="//use.fontawesome.com/releases/v5.0.7/css/all.css">


    <!-- Fonts -->

    <link href="https://fonts.googleapis.com/css2?family=Kalam&family=Pangolin&display=swap" rel="stylesheet">

    <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">


    <!-- JQuery -->

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>


    <title>Welcome Home</title>

</head>

<body>

    <div class="placeholder"></div>

    <script>

        $(function(){

            $('.placeholder').load("nav.html");

        });

    </script>    


    hello world



    <script src="js/main.js"></script>


</body>

</html>

about.php(以前的)与除了它有几个段落标签外index.html基本相同。home.php


子衿沉夜
浏览 144回答 1
1回答

慕村225694

我不清楚此时有什么不起作用,所以我不妨分享一个我在本地的工作示例。我正在访问我的站点http://localhost/so/,然后转到该 URL 将加载index我拥有的任何页面。我在/so目录中有 3 个文件:nav.html(我删除了你的<body>标签,因为那些已经存在于其他文件中):<header>&nbsp; &nbsp; <div class="logo">&nbsp; &nbsp; &nbsp; &nbsp; <h1 class="logo-text"><a href="home.php">Welcome!</a></h1>&nbsp; &nbsp; </div>&nbsp; &nbsp; <i class="fa fa-bars menu-toggle"></i>&nbsp; &nbsp; <ul class="nav">&nbsp; &nbsp; &nbsp; &nbsp; <li><a href="home.php">Home</a></li>&nbsp; &nbsp; &nbsp; &nbsp; <li><a href="about.php">About</a></li>&nbsp; &nbsp; </ul></header>home.php(可在 localhost/so/home.php 访问):<!DOCTYPE html><html><head>&nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; <meta name="viewport" content="width=device-width, initial-scale=1.0">&nbsp; &nbsp; <meta http-equiv="X-UA-Compatible" content="ie-edge">&nbsp; &nbsp; <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">&nbsp; &nbsp; <link rel="stylesheet" href="css/style.css?v=<?php echo time(); ?>">&nbsp; &nbsp; <!-- Font Awesome -->&nbsp; &nbsp; <link rel="stylesheet" href="//use.fontawesome.com/releases/v5.0.7/css/all.css">&nbsp; &nbsp; <!-- Fonts -->&nbsp; &nbsp; <link href="https://fonts.googleapis.com/css2?family=Kalam&family=Pangolin&display=swap" rel="stylesheet">&nbsp; &nbsp; <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">&nbsp; &nbsp; <!-- JQuery -->&nbsp; &nbsp; <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>&nbsp; &nbsp; <title>Welcome Home</title></head><body>&nbsp; &nbsp;<?php include "./nav.html"; ?>&nbsp; &nbsp; hello world home&nbsp; &nbsp; <script src="js/main.js"></script></body></html>about.php(可在 localhost/so/about.php 访问):<!DOCTYPE html><html><head>&nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; <meta name="viewport" content="width=device-width, initial-scale=1.0">&nbsp; &nbsp; <meta http-equiv="X-UA-Compatible" content="ie-edge">&nbsp; &nbsp; <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">&nbsp; &nbsp; <link rel="stylesheet" href="css/style.css?v=<?php echo time(); ?>">&nbsp; &nbsp; <!-- Font Awesome -->&nbsp; &nbsp; <link rel="stylesheet" href="//use.fontawesome.com/releases/v5.0.7/css/all.css">&nbsp; &nbsp; <!-- Fonts -->&nbsp; &nbsp; <link href="https://fonts.googleapis.com/css2?family=Kalam&family=Pangolin&display=swap" rel="stylesheet">&nbsp; &nbsp; <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">&nbsp; &nbsp; <!-- JQuery -->&nbsp; &nbsp; <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>&nbsp; &nbsp; <title>Welcome About</title></head><body>&nbsp; &nbsp;<?php include "./nav.html"; ?>&nbsp; &nbsp; hello world about&nbsp; &nbsp; <script src="js/main.js"></script></body></html>如果我重命名home.php为,index.php那么我可以转到localhost/so/或localhost/so/index.php访问该文件。稍微相关:您不一定要用作time()CSS 缓存破坏变量,因为它根本不会缓存。$css_cache_bust = "2020061001";您应该使用手动调整 (ie )值的变量,href="css/style.css?v=<?= $css_cache_bust; ?>"这样您就可以根据需要逐步调整它。
打开App,查看更多内容
随时随地看视频慕课网APP