使用rewriteengineer配置通配符SSL vhosts



我目前正在努力配置一个有许多通配符子域的域。我想确保以下内容发生。

  1. 所有*:80流量被转换为HTTPS
  2. 中对应的fqdn域名例如:

http://jane.example.com→https://jane.example.com

http://jack.example.com→https://jack.example.com

http://www.example.com→https://www.example.com

注意事项:

。我的ssl证书是一个通配符,所以如果没有主机,我要确保重定向包括主机的www。*:80和*:443

http://example.com→https://www.example.com

https://example.com→https://www.example.com

vhost看起来像:

<VirtualHost 108.161.x.x:443>
Servername %1.example.com
ServerAlias www.example.com
DocumentRoot /home/sites/example.com/www
ErrorLog logs/md-ssl-error_log
CustomLog logs/md-ssl-access_log common
SSLEngine on
SSLCertificateFile /etc/ssl/kl_crt.crt
SSLCertificateKeyFile /path/to/kl_pk.key
SSLCertificateChainFile /path/to/kl_cab.crt
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
</VirtualHost>

这里的常规http流量

<Virtualhost 108.161.x.x:80>
ServerName %1.example.com
RewriteEngine On
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
</VirtualHost>
谁知道我的代码有什么问题?

您可以尝试这样做:

ServerName example.com
ServerAlias %1.example.com

DocumentRoot /home/sites/example.com/%1

最新更新