2017-08-04 104 views
0

我JAVE的服務器有多個目錄根:的Apache,根,子域和子目錄

  • /網站
  • /論壇
  • /維基
  • 等等...

當我訪問該網站時,網址是mysite.org/site或mysite.org/forum。

我想什麼太配置我的.htaccess的行爲是這樣的:

  • 網站目錄作爲根目錄:該URL是mysite.org/blabla,但它顯示的mysite的內容.ORG /網站/布拉布拉
  • 其他目錄作爲子域:URL是forum.mysite.org但它顯示mysite.org/forum

我不能設法得到這個工作.. 。

目前我的.htaccess是這樣的:

RewriteEngine On 

# Map http://www.example.com to /site. 
RewriteRule ^$ /site/ [L] 

# Map http://www.example.com/x to /site/x unless there is a x in the web root. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !^/site/ 
RewriteRule ^(.*)$ /site/$1 

# Add trailing slash to directories without them so DirectoryIndex works. 
# This does not expose the internal URL. 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteCond %{REQUEST_FILENAME} !/$ 
RewriteRule ^(.*)$ $1/ 

# Disable auto-adding slashes to directories without them, since this happens 
# after mod_rewrite and exposes the rewritten internal URL, e.g. turning 
# http://www.example.com/about into http://www.example.com/site/about 
DirectorySlash off 

有人可以幫我嗎?

回答

0

我不確定這是否可以用.htaccess。無論如何,我認爲最好的/正確的方法是將子目錄拆分成由同一個Apache服務的不同網站。

如:

移動/var/www/mysite.org/wiki/*到 - >/var/www/wiki.mysite.org/*
移動/var/www/mysite.org/forum/*到 - >/var/www/forum.mysite.org/*
保持/var/www/mysite.org there

再建如Apache配置:

mysite.conf:

# domain: mysite.org 
# public: /var/www/mysite.org 

<VirtualHost *:80> 
    # Admin email, Server Name (domain name), and any aliases 
    ServerAdmin [email protected] 
    ServerName mysite.org 
    ServerAlias www.mysite.org *.mysite.org mysite.org 

    # Index file and Document Root (where the public files are located) 
    DirectoryIndex index.html index.php 
    DocumentRoot /var/www/mysite.org/ 

    <Directory /var/www/mysite.org> 
    Options -Indexes 
    Options +FollowSymLinks 
    Options -Includes 
    Options -ExecCGI 
    AllowOverride All 
    Require all granted 
    </Directory> 

    # Log file locations 
    LogLevel warn 
    ErrorLog /var/log/apache2/mysite.org_error.log 
    CustomLog /var/log/apache2/mysite.org_access.log combined 
</VirtualHost> 

wiki.conf:

# domain: wiki.mysite.org 
# public: /var/www/wiki.mysite.org 

<VirtualHost *:80> 
    # Admin email, Server Name (domain name), and any aliases 
    ServerAdmin [email protected] 
    ServerName wiki.mysite.org 
    ServerAlias wiki.mysite.org 

    # Index file and Document Root (where the public files are located) 
    DirectoryIndex index.html index.php 
    DocumentRoot /var/www/wiki.mysite.org/ 

    <Directory /var/www/wiki.mysite.org> 
    Options -Indexes 
    Options -FollowSymLinks 
    Options -Includes 
    Options -ExecCGI 
    AllowOverride All 
    Require all granted 
    </Directory> 

    # Log file locations 
    LogLevel warn 
    ErrorLog /var/log/apache2/wiki.mysite.org_error.log 
    CustomLog /var/log/apache2/wiki.mysite.org_access.log combined 
</VirtualHost> 

這樣你可以指定不同的設置(日誌文件,配置包括等)在每個站點的基礎,並做很酷的東西喜歡用mpm_itk運行每個網站有不同的UID/GID。

+0

不幸的是,我不在專用服務器上,所以我無法更改conf文件。這就是爲什麼我想通過編輯htaccess來做到這一點。 –