Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 将子目录视为Apache的根目录_Html_Apache - Fatal编程技术网

Html 将子目录视为Apache的根目录

Html 将子目录视为Apache的根目录,html,apache,Html,Apache,我找不到做我想做的事的方法。我想在http://example.com/MyNewProject 在每个网页中,我都包含一个文件,用于导入样式表、JavaScript等的所有内容。我不想每次都提供完整的路径,我只想能够执行/MyStylesheet.css 我的主要网站文档根是/var/www/html/example,我的新项目目录存储在/var/www/html/example/MyNewProject中 当我执行/MyStylesheet.css时,我需要的是导入,而不是转到我的服务器主w

我找不到做我想做的事的方法。我想在
http://example.com/MyNewProject

在每个网页中,我都包含一个文件,用于导入样式表、JavaScript等的所有内容。我不想每次都提供完整的路径,我只想能够执行
/MyStylesheet.css

我的主要网站文档根是
/var/www/html/example
,我的新项目目录存储在
/var/www/html/example/MyNewProject

当我执行
/MyStylesheet.css
时,我需要的是导入,而不是转到我的服务器主web目录,它将转到/var/www/html/example/MyNewProject以获取css

我已尝试将以下内容添加到我的Apache配置文件中:

Alias /NewProjectTemplate "/var/www/html/example/NewProjectTemplate"
Alias /NewPRojectTemplate/ "/var/www/html/example/NewProjectTemplate"

<Directory "/var/www/html/example/NewProjectTemplate">
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        XBitHack On
        Order allow,deny
        Allow from all
</Directory>
因此,需要澄清的是,如果#include file=
includes/imports.html
SSI指令有效,并且/StyleSheet.css成功导入,即使它具有前导斜杠。如果我将/添加到SSI的路径,则不会导入它

但这是它变得更奇怪的地方


如果我随后将另一个文件添加到子目录,例如
NewProjectTemplate/MySubDirectory
,然后将SSI添加为../includes/imports.html,它仍然无法工作。这就像#include file SSI指令期望文件位于同一工作目录中一样。

那么,您在虚拟主机中尝试过这样做吗

<VirtualHost *:80>
    ServerAdmin emailaddress@domain.com
    DocumentRoot "/var/www/html/example/"
    ServerName example.local
    ServerAlias example.local
    <Directory "/var/www/html/example/">
        Options All Includes Indexes FollowSymLinks
        Order allow,deny
        Allow from all
        AllowOverride All
    </Directory>

    Alias /NewProjectTemplate /var/www/html/example/NewProjectTemplate
    <Directory "/var/www/html/example/NewProjectTemplate">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

服务器管理员emailaddress@domain.com
DocumentRoot“/var/www/html/example/”
ServerName example.local
ServerAlias example.local
所有选项都包括索引和符号链接
命令允许,拒绝
通融
允许超越所有
别名/NewProjectTemplate/var/www/html/example/NewProjectTemplate
命令允许,拒绝
通融

希望这次能有所帮助。

只是偶然发现了这个非常古老的威胁。 如果只想将子目录视为根目录,则不需要主机或别名

这样做的方法是修改httpd.conf,您会发现

<Directory>

只需更新此行并添加

<Directory "your/server/root/original_path/subpath">
    # your options
</Directory>

#你的选择

这不是我要问的,这实际上是在改变我的Web服务器的域。URL仍然应该是,但NewProjectTemplate被视为根。谢谢,我现在尝试了这个,但似乎不起作用。我仍然收到PHP错误,说它找不到/includes/imports.html/包括位于NewProjectTemplate根目录内。所以我想它一定是在网络服务器上看的,我想你很接近了。尝试在浏览器控制台中查看它正在查找的路径…浏览器控制台显示它将进入
http://example.com/StyleSheet.css
而不是
http://example.com/NewProjectTemplate/StyleSheet.css
尝试在浏览器中访问别名url,以检查其是否真的有效。。。如果问题继续发生,您可以定义一个变量,该变量包含一个基本url。。。在配置文件中设置变量newProjectTemplate=并像newProjectTemplate一样调用。“StyleSheet.css”…只是一个解决方法..在我们的PHP代码中,我们创建了一个环境对象来分析当前URL,并根据URL中找到的子目录确定我们的“baseWebPath”。这是基于模板的解决方案的基础,无论脚本的位置如何,我们都可以使用相同的相对路径(如“javascript/myscript.js”)包含javascript和css。想必,您正在试图避免像“./javascript/myscript.js”和“../../javascript/myscript.js”这样的引用。我的建议是采用基于PHP的方法,而不是尝试寻找基于Apache的解决方案。
<link rel="stylesheet" type="text/css" href="/StyleSheet.css">
<link rel="stylesheet" type="text/css" href="/navigation/top-nav.css">
<link rel="stylesheet" type="text/css" href="/navigation/side-nav.css">
<script type="text/javascript" src="/scripts/jquery.js"></script>
<script type="text/javascript" src="/scripts/menu.js"></script>
<VirtualHost *:80>
    ServerAdmin emailaddress@domain.com
    DocumentRoot "/var/www/html/example/"
    ServerName example.local
    ServerAlias example.local
    <Directory "/var/www/html/example/">
        Options All Includes Indexes FollowSymLinks
        Order allow,deny
        Allow from all
        AllowOverride All
    </Directory>

    Alias /NewProjectTemplate /var/www/html/example/NewProjectTemplate
    <Directory "/var/www/html/example/NewProjectTemplate">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
<Directory>
<Directory "your/server/root/original_path/subpath">
    # your options
</Directory>