【问题标题】:XAMPP - PHP Going Outside Main Site FolderXAMPP - PHP 超出主站点文件夹
【发布时间】:2017-12-24 21:25:07
【问题描述】:

所以我的网站结构是这样的

C:/xampp/htdocs/Testing/index.php

此 PHP 文件包含如下所示的代码

<div>     
<?php require 'php/header.php';
?>
</div>

在 header.php 中,它调用了

<link rel="stylesheet" href="../css/styles.css">

一旦所有这些都上传到托管的 Web 服务器,它就可以正常工作了,因为该站点无法访问根文件夹之外的文件,但是在 XAMPP 中预览我的站点时,代码被破坏了,因为它正在寻找不在其中的 css/styles.css我的站点文件夹,但在 C:/xampp/htdocs/css/ 而不是 C:/xampp/htdocs/Testing/css/

这使我的主 index.php 的预览损坏,但所有其他子页面(如 flavor/index.php 和 locations/index.php)都可以正常工作。如果有人遇到过这个问题或能想到解决办法,请告诉我,因为这让我很头疼。谢谢。

【问题讨论】:

    标签: php apache .htaccess xampp dreamweaver


    【解决方案1】:

    好的。我建议你一个解决方案。在您的 xampp 中创建一个 VirtualHost,这可能会解决您的问题。

    在你xampp\apache\conf\extra\httpd-vhosts.conf,添加这个:

    <VirtualHost *:80>
        DocumentRoot C:/xampp/htdocs/Testing
        ServerName www.testing.com
    </VirtualHost>
    

    现在,在你的C:\WINDOWS\system32\drivers\etc\ 打开“hosts”文件:

    127.0.0.1       www.testing.com
    

    最后,在您的C:\xampp\apache\conf\httpd.conf 中,滚动到 VirtualHost 行,它应该如下所示:

    #Virtual hosts
    Include conf/extra/httpd-vhosts.conf
    

    为此更改您的CSS:

    <link rel="stylesheet" href="/css/styles.css">
    

    重新启动您的 xampp 服务器,然后在浏览器中转到 www.testing.com

    尽情享受吧!

    【讨论】:

    • 我认为文档根目录应该是根文件夹。 DocumentRoot C:/xampp/htdocs/Testing
    【解决方案2】:

    为什么不设置基本路径?

    <base href="localhost/Testing">
    

    这可能是最简单的解决方案。 只需将此规则添加到“head”标签内的索引中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 2017-12-29
      • 2011-05-31
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      相关资源
      最近更新 更多