gpt4 book ai didi

使用通配符子域的 Apache SSL 重写

转载 作者:太空宇宙 更新时间:2023-11-03 12:52:46 26 4
gpt4 key购买 nike

我正在尝试使用将执行以下操作的 RewriteEngine 在 Apache 中设置 SSL 重定向:

我的理由是,我正在开发一个在发布前使用免费 SSL 证书的项目。该证书涵盖基本域,但不包含通配符子域,每次我访问其中一个子域时都需要绕过警告,这很痛苦。

编辑:我相信我已经接近这里了,但我仍然无法使 HTTPS 到 HTTP 重定向正常工作。

RewriteEngine on
# Redirect domain and www to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} =mydomain.com [or]
RewriteCond %{HTTP_HOST} =www.mydomain.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect wildcard subdomains to HTTP
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

最佳答案

想通了。通过将这些规则从 sites-available/default 文件移动到网站根目录中的 .htaccess,我能够使其正常工作。

RewriteEngine on
# Redirect domain and www to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} =mydomain.com [or]
RewriteCond %{HTTP_HOST} =www.mydomain.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect wildcard subdomains to HTTP
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !=www.mydomain.com
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

关于使用通配符子域的 Apache SSL 重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21560603/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com