动态虚拟主机 - 基于域

时间:2018-02-05 14:50:45

标签: apache .htaccess virtualhost

我有我的虚拟主机

<VirtualHost *:80>
ServerAdmin webmaster@localhost
UseCanonicalName Off
VirtualDocumentRoot /home/xxx/www/%0
AssignUserID UserName xxx
<Directory /home/xxx/www/>
 Options -Indexes +FollowSymLinks
 AllowOverride All
 Allow from all
 Require all granted
</Directory>
ServerAlias xxx.com *.xxx.com
php_admin_value open_basedir "/home/xxx/www:/home/xxx/tmp"
php_admin_value upload_tmp_dir /home/xxx/tmp
php_admin_value session.save_path /home/xxx/tmp
ErrorLog /home/xxx/error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn
CustomLog /home/xxx/access.log combined
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

我有网站:www.xxx.com,preview1.xxx.com,preview2.xxx.com,preview3.xxx.com,somerandomsubdomain.xxx.com

每个域名和子域名(如www.xxx.com和previev1.xxx.com)都指向正确的文档根目录,因此我可以动态添加子域名。

Quiestion是:我如何轻易地为preview3.xxx.com指出不是/home/xxx/www/preview3.xxx.com,而是指向/home/xxx/www/preview3.xxx.com/www?

1 个答案:

答案 0 :(得分:1)

在同一个文件中创建另一个VirtualHost,高于当前文件。使用相同的配置,只需更改这两个值:

#VirtualDocumentRoot /home/xxx/www/%0
DocumentRoot /home/xxx/www/preview3.xxx.com/www

#ServerAlias xxx.com *.xxx.com
ServerName preview3.xxx.com