我有以下虚拟主机(在apache2.conf文件中)从AWS上的单个目录加载所有子域
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName mydevsite.com
ServerAlias mydevsite.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/apps
ServerName mydevsite.com
ServerAlias *.mydevsite.com
</VirtualHost>
它不起作用,子域仍然指向html目录
我也试过跟随htaccess然后它给了我500错误
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.website\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.website\.com$
RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
RewriteRule ^(.*)$ /%1/$1 [QSA]
我的简单要求是从根目录加载主域,从apps目录加载所有子域
答案 0 :(得分:1)
查看文档:{{3}},Using Name-based Virtual Hosts,ServerName Directive
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.mydevsite.com
ServerAlias mydevsite.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/apps
ServerName apps.mydevsite.com
ServerAlias *.mydevsite.com
</VirtualHost>