我有一个域名domain.com
,并创建了一个子域名“forum.domain.com”。我正在使用Apache2
并将其添加A record
到 DNS 记录中,virtualNameServer
如下所示:
<VirtualHost *:80>
ServerName forum.domain.com
DocumentRoot /var/www/vanilla
<Directory /var/www/vanilla>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
allow from all
</Directory>
ErrorLog "|/usr/sbin/rotatelogs /etc/httpd/logs/vanilla-error.%Y-%m-%d.log 86400"
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/vanilla-access.%Y-%m-%d.log 86400" "%h %l %u %t %D \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
</VirtualHost>
在子域中,我安装了Vanilla Forum Software
。但是,现在的问题是,每当我转到http://domain.com
或 时http://www.domain.com
,它都会转到。默认情况下 中http://forum.domain.com
是:.htaccess
forum.domain.com
# Original
# If you modify this file then change the above line to: # Modified
<IfModule mod_rewrite.c>
RewriteEngine On
# Certain hosts may require the following line.
# If vanilla is in a subfolder then you need to specify it after the /.
# (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum)
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L]
</IfModule>
请帮忙。提前致谢。
答案1
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
使用基于名称的虚拟主机
主要宿主消失
如果您要将虚拟主机添加到现有 Web 服务器,还必须为现有主机创建一个块。此虚拟主机中包含的 ServerName 和 DocumentRoot 应与全局 ServerName 和 DocumentRoot 相同。在配置文件中首先列出此虚拟主机,以便它充当默认主机。
答案2
您需要两个虚拟主机,在您的示例中,它看起来像这样:
<VirtualHost *:80>
ServerName forum.domain.com
DocumentRoot /var/www/vanilla
<Directory /var/www/vanilla>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
allow from all
</Directory>
ErrorLog "|/usr/sbin/rotatelogs /etc/httpd/logs/vanilla-error.%Y-%m-%d.log 86400"
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/vanilla-access.%Y-%m-%d.log 86400" "%h %l %u %t %D \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
</VirtualHost>
<VirtualHost *:80>
ServerName domain.com
DocumentRoot /var/www/main
ErrorLog "|/usr/sbin/rotatelogs /etc/httpd/logs/domain-error.%Y-%m-%d.log 86400"
CustomLog "|/usr/sbin/rotatelogs /etc/httpd/logs/domain-access.%Y-%m-%d.log 86400" "%h %l %u %t %D \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
</VirtualHost>