我已经使用本地服务器几个月了,每次启动新项目时,我都需要使用服务器的根目录而不是项目的根目录。
在我的服务器上,我有:
htdocs
-- project1
---- images
---- js
---- css
-- project2
// etc. //
当我转到 rawox.co.cc(这是我在家里的开发服务器)时,它将重定向到投资组合文件夹(rawox.co.cc/portfolio/)另一个项目是Menology(rawox.co.cc/menology/)。在我的css中,对于这些项目,我必须使用background-image: url(../images/logo.png;
。当我将项目上传到公共服务器时,css 因为这些../
而停止工作。
我个人的想法是,这是由于在我的 apache 设置中http://rawox.co.cc/
设置为文档根这一事实引起的。我将如何解决这个问题?
您可以在 httpd.conf 中使用虚拟主机。
<VirtualHost 10.1.2.3:80>
ServerAdmin webmaster@host.example.com
DocumentRoot /www/docs/host.example.com
ServerName host.example.com
ErrorLog logs/host.example.com-error_log
TransferLog logs/host.example.com-access_log
</VirtualHost>
为每个项目创建一个单独的 project1-vhost.conf 文件,并将其包含在
include project1-vhost.conf
因此,您可以轻松激活和停用每个项目
http://httpd.apache.org/docs/2.0/vhosts/examples.htmlhttp://httpd.apache.org/docs/2.2/en/mod/core.html#virtualhost
//编辑
Alias /project1 /path/to/project
<Location /path/to/project>
Order Allow, Deny
Allow from All
...
</Location>