apache - SSL 通配符 Apache

标签 apache .htaccess ssl wildcard

我有一个 SAAS,我需要在其中动态创建多个子域(注意:有很多子域,我不知道哪些会自动生成)。所以我不能为每个人重复这个:

<VirtualHost *:80>
    ServerName a1.app.example.com
    Redirect / https://a1.app.example.com
</VirtualHost>

有没有办法将 http 中的每个子域重定向到 https?。类似于“重定向/https://*.app.example.com”

<VirtualHost *:80>
    ServerName app.example.com
    Redirect / https://*.app.example.com
</VirtualHost>

<VirtualHost *:80>
    ServerName app.example.com
    ServerAlias *.app.example.com
    DirectoryIndex index.php
    DocumentRoot /var/www/xxxxxxx

    SSLEngine on
    SSLCertificateFile /etc/ssl/xxxxx.crt
    SSLCertificateKeyFile /etc/ssl/xxxx.key
    SSLCertificateChainFile /etc/ssl/xxxx.crt
 </VirtualHost>

最佳答案

将其添加到您的主虚拟主机:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,QSA,R=301]

并确保 mod_rewrite 处于事件状态。您可以使用 a2enmod rewrite 命令激活它。

关于apache - SSL 通配符 Apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43645698/

相关文章:

.htaccess - Opencart - 如何从网址中删除 "en-gb"

javascript - 让后退按钮在单页网站中工作并实现 "speaking"URL

php - 德鲁帕尔 7 : Localhost/user link defaults to website/user

c# - 指定用于 WSHttpBinding 客户端连接的 SSL 协议(protocol)版本

java - 自动获取中间证书的代码

apache httpd LogFormat 不支持 strftime 格式

Apache - 权限策略标题错误 : Parse of permission policy failed because of errors reported by strctured header parser

apache - .htaccess 使用 request_uri 和 query_string 中的参数

apache - Elasticsearch 查询上下文与过滤上下文

ssl - 使用 Spring-WS 的客户端 SSL