我可能会问一个非常愚蠢的问题,但我找不到办法去做我想做的事.
我想将项目上传到我的服务器 http://example.com/MyNewProject
在每个网页中,我都包含一个文件,该文件执行StyleSheets,javascript等的所有导入.我不想每次只想提供完整路径 /MyStylesheet.css
我的主要网站文件根目录/var/www/html/example和我的新项目目录存储在其中/var/www/html/example/MyNewProject.
我想要的是在我导入时,/MyStylesheet.css而不是去我的服务器主网站目录,它将转到/ 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>
Run Code Online (Sandbox Code Playgroud)
遗憾的是这没有用,所以我也尝试将以下内容添加到我的virtualhosts文件中
<VirtualHost *:80>
DocumentRoot /var/www/html/example/NewProjectTemplate
ServerName example.com/NewProjectTemplate
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
我在谷歌上环顾四周但找不到具体的东西,我发现的唯一一件事就是使用重写引擎,但这看起来有点过于复杂,而且对我的需求也是如此.
感谢您的任何帮助,您可以提供.
UPDATE
好吧,我还有一点,虽然不是很多,我敢肯定它不应该是这么复杂.
而不是使用虚拟主机,我现在使用别名,下面是我添加到我的httpd.conf文件中的内容
DocumentRoot "/var/www/html"
Alias /NewTemp/ "/var/www/html/example/NewProjectTemplate/"
Alias /NewTemp "/var/www/html/example/NewProjectTemplate"
<Directory "/var/www/html/example/NewProjectTemplate/">
Options FollowSymLinks Includes
AllowOverride all
</Directory>
<Directory "/var/www/html/example/NewProjectTemplate">
Options FollowSymLinks Includes
AllowOverride all
</Directory>
Run Code Online (Sandbox Code Playgroud)
在我的SSI中的HTML代码中,我正在执行以下操作:
<!--#include file="includes/imports.html"-->
Run Code Online (Sandbox Code Playgroud)
如您所见,这是一个相对路径,而且包含在NewProjectTemplate的根目录中.但是,这是一个模板文件,因此我希望它始终转到根目录以查找文件,因此无论网站有多深,它都可以保证工作.例如,如果我将行更改为下面的I,则会出现错误error processing directive
<!--#include file="/includes/imports.html"-->
因此,即使它没有/但没有使用斜杠,如果我不包含斜杠,所以这个导入然后工作,imports.html文件中的导入工作,即使它们确实包含前导斜杠,所以它始终去根.下面是我的HTML导入文件
<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>
Run Code Online (Sandbox Code Playgroud)
所以只是为了澄清,如果#include文件= includes/imports.htmlSSI指令工作,并且/StyleSheet.css成功导入,即使它有前导斜杠.如果我在SSI的路径中添加一个/那么它就不会被导入.
但这里有更奇怪的地方.
如果我然后将另一个文件添加到子目录,例如NewProjectTemplate/MySubDirectory然后将SSI添加到../includes/imports.html它仍然不起作用.它与#include文件一样,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>
Run Code Online (Sandbox Code Playgroud)
希望这次能有所帮助..