2012-04-26 110 views
4

我有一个本地服务器几个月了,每次我开始一个新项目我需要使用服务器的根目录,而不是项目的根目录。每个项目documentroot

在我的服务器我有:

htdocs 
-- project1 
---- images 
---- js 
---- css 
-- project2 
// etc. // 

当我去rawox.co.cc(这是在家里我的开发服务器),它会重定向到投资组合文件夹(rawox.co.cc/组合/)另一个项目是menology(rawox.co.cc/menology/)。在我的这些项目的CSS中,我必须使用background-image: url(../images/logo.png;。当我将项目上传到公共服务器时,由于那些../,css停止工作。

我个人的想法是,它是由http://rawox.co.cc/在我的apache设置中被设置为DocumentRoot的事实引起的。我将如何解决这个问题?

回答

1

你可以在你的httpd.conf中使用虚拟主机。

<VirtualHost 10.1.2.3:80> 
    ServerAdmin [email protected] 
    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 
在httpd.conf文件

。所以你可以很容易地启用和停用每个项目

http://httpd.apache.org/docs/2.0/vhosts/examples.html http://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> 
+0

我知道这件事,但我不想使用Servername host.example.com,我想要Servername example.com/host。 – 2012-05-23 21:34:12

+0

然后你可以尝试 Alias/project1/path/to/project1 Order Allow,Deny ... Marduk 2012-05-23 23:33:14