我设置了一些虚拟主机:
website1.com
try.website1.com
website2.com
try.website2.com
一切工作正常,但如果我写了一个错误的第三级,如“qwerty.website1.com”或“qwerty.website2.com”,我想将用户重定向到相应的域,而不是一般页面。
我该如何配置 000-default?或者还有其他方法可以做到吗?
这是我的 000-default:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName 12.123.123.123
DocumentRoot "/var/www/"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
答案1
Apache<VirtualHost>
从头开始搜索定义,并在第一次匹配时停止。您可以利用这一点。
<Virtualhost *:80>
ServerName try.website1.com
.
.
.
</VirtualHost>
<Virtualhost *:80>
ServerName website1.com
ServerAlias *.website1.com
.
.
.
</VirtualHost>
<Virtualhost *:80>
ServerName try.website2.com
.
.
.
</VirtualHost>
<Virtualhost *:80>
ServerName website2.com
ServerAlias *.website2.com
.
.
.
</VirtualHost>
这会将他们自己的虚拟主机以及任一域中的任何其他内容定向try.webste1.com
到try.website2.com
该域的主虚拟主机。