我已经配置了 Apache2
<VirtualHost *:80>
ServerName y.com
</VirtualHost>
和子域名
<VirtualHost *:443>
ServerName x.y.com
</VirtualHost>
目标是https://xycom仅通过 SSL 访问。但当我输入任何其他子域名时,例如https://any.y.com我看到的是同一个页面https://xycom
我如何禁用任何网址,例如https://any.y.com显示与https://xycom。我认为这样的网站根本就不应该被访问。
答案1
您必须在端口 443 上仅为 xycom 设置虚拟主机,并在端口 80 上仅为 y.com 设置虚拟主机。
Namevirtualhost *:80
Namevirtualhost *443
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "conf/ssl.crt/certificate.crt"
SSLCertificateKeyFile "conf/ssl.key/certificate.key"
SSLCertificateChainFile "conf/ssl.crt/chain-file.ca-bundle"
ServerAdmin [email protected]
DocumentRoot "C:/apache/htsecure/"
ServerName secure.u4ik.us
ServerAlias secure.u4ik.us
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "C:/apache/htdocs/"
ServerName u4ik.us
ServerAlias www.u4ik.us
</VirtualHost>
请注意两个不同的文档根。还请注意,它们监听特定域。要使所有子域都转到 xycom,请使用 mod_rewrite:
将其弹出到.htaccess 文件中:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule (.*) %2/$1 [L]
</IfModule>