2013-02-13 117 views
0

我不能管理設置在URL中的虛擬主機與子目錄... 我需要在地址這樣運行了我的項目:Apache的虛擬主機URI與DIR

http://www.projects.loc/project1/ 這應該模仿上安裝Web服務器地址在哪裏會像

http://www.someServer.com/projects/project1/

我需要那麼它可以追溯到www.projects.loc/project1/

調整重定向到「/」在HOSTS.TXT我:

127.0.0.1  www.projects.loc 

虛擬主機已啓用,並且在httpd-vhosts.conf看起來是這樣的:

NameVirtualHost *:80 

<VirtualHost *:80> 
    DocumentRoot "D:/Projects/Project1/public/"   
    ServerName www.projects.loc/project1/ 
</VirtualHost> 

我缺少什麼?

編輯:的.htaccess看起來是這樣的:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php [NC,L] 

的應用程序在乾淨的域名運行正常,但我不能管理它配置到 上domain.com/some_dir/

運行

編輯:
解決了這個!

NameVirtualHost *:80 

    <Directory "D:/Projects"> 
     allow from all 
    </Directory> 

    <VirtualHost *:80> 
     DocumentRoot "D:/Projects"  
     ServerName www.projects.loc/ 

     Alies /project1 /Project1/public/ 
    </VirtualHost> 

注:這是最低配置僅用於開發環境不錯,離@ M-z對生產環境現狀全部細節
檢查接受ansler。

+1

什麼重複寫你試過嗎? – 244an 2013-02-13 22:51:11

回答

1

可能你已經解決了這個問題。反正,我今天找了類似的事情,所以我記錄下這裏的解決方案:

你不想在服務器名

ServerName www.projects.loc/project1/

寫斜線如果你只是有一個項目,叫「PROJECT1」你可以很容易地用「SERVERPATH」所做的工作,你的虛擬主機的配置會再看看這樣的:

<VirtualHost *:80> 
ServerName projects.loc 
ServerAlias www.projects.loc 
ServerPath /project1/ 
DocumentRoot /PATH/public_html 
ErrorLog /PATH/error_log 
CustomLog /PATH/access_log combined 
DirectoryIndex index.html index.htm index.php index.php4 index.php5 
<Directory /PATH/public_html> 
Options -Indexes +IncludesNOEXEC +FollowSymLinks 
allow from all 
</Directory> 
</VirtualHost> 

通過你能夠掛載目錄projects.loc/PROJECT1的SERVERPATH

無論如何,假設你有幾個你想綁定到projects.loc/project1,projects.loc/project2等的項目(project1,project2),使用「Alias」。然後,您的虛擬主機配置文件應該是這樣的:

<VirtualHost *:80> 
ServerName projects.loc 
ServerAlias www.projects.loc 
DocumentRoot /PATH/public_html 
ErrorLog /PATH/error_log 
CustomLog /PATH/access_log combined 
DirectoryIndex index.html index.htm index.php index.php4 index.php5 
<Directory /PATH/public_html> 
Options -Indexes +IncludesNOEXEC +FollowSymLinks 
allow from all 
</Directory> 

Alias /project1 "/PATH/public_html/project1" 
<Directory "/PATH/public_html/project1"> 
DirectoryIndex index.html index.htm index.php index.php4 index.php5 
Options -Indexes +IncludesNOEXEC +FollowSymLinks 
allow from all 
</Directory> 

Alias /project2 "/PATH/public_html/project2" 
<Directory "/PATH/public_html/project2"> 
DirectoryIndex index.html index.htm index.php index.php4 index.php5 
Options -Indexes +IncludesNOEXEC +FollowSymLinks 
allow from all 
</Directory> 
</VirtualHost> 

您的應用程序在文件夾/ PATH /的public_html/PROJECT1鋪設然後將可在projects.loc/PROJECT1,你的應用奠定了文件夾/ PATH /的public_html/project2將在projects.loc/project2等中提供。

我寧願爲不同的應用程序使用不同的子域。這有利於爲每個子域主機配置自己的配置文件,這也使得錯誤和訪問日誌處理更容易。通過使用別名,配置不同的錯誤和訪問日誌將更加困難,如果您想要每個應用程序都有它們。

延伸閱讀:
關於別名:http://httpd.apache.org/docs/current/mod/mod_alias.html
關於SERVERPATH:http://httpd.apache.org/docs/2.2/vhosts/examples.html#serverpath

+0

我現在解決了這個問題,當我檢查你的答案..這是正確的,但詳細..所以我沒有得到它的第一次:) – 2013-07-17 08:42:37