gpt4 book ai didi

.htaccess - 在 .htaccess 中强制使用 SSL 和 WWW

转载 作者:太空宇宙 更新时间:2023-11-03 13:18:30 24 4
gpt4 key购买 nike

我四处寻找强制 SSL 和 www 的方法。但我发现的许多解决方案都没有奏效。目前我正在尝试这个:

RewriteCond %{HTTP_HOST} ^domain\.co\.uk$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://www.domain.co.uk/$1 [R,L]
  • domain.co.uk -> https://www.domain.co.uk
  • www.domain.co.uk -> https://domain.co.uk
  • https://domain.co.uk -> https://domain.co.uk 存在 SSL 错误

(空格是因为我太新,无法发布超过 2 个链接)。

有没有办法做到这一点?在尝试了至少 10 个不同的示例之后,令我惊讶的是它们最终都在最后一个上失败了。

最佳答案

您的问题是您指定了 HTTP 主机但在您的条件中缺少 HTTPS 主机。像这样:

RewriteCond %{HTTP_HOST} ^domain\.co\.uk$ [OR]
RewriteCond %{HTTPS_HOST} ^domain\.co\.uk$ [OR]
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://www.domain.co.uk/$1 [R,L]

应该这样做。

关于.htaccess - 在 .htaccess 中强制使用 SSL 和 WWW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14693739/

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