2017-08-04 103 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来做到这一点。 –