.htaccess - 使用 SSL 重写规则不起作用

标签 .htaccess ssl

我想将 https://example.com 重定向到 https://www.example.com

如果我转到 https://example.com/aboutus

它还应该重定向到 https://www.example.com/aboutus

目前,我在 .htaccess 中有这个,但它会使 ssl 证书消失。

RewriteCond %{HTTPS} off
RewriteCond %{DOCUMENT_ROOT}/../.force_ssl -f
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

最佳答案

只需在您的 .htaccess 顶部尝试这条规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

确保清除浏览器缓存。

关于.htaccess - 使用 SSL 重写规则不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33490980/

相关文章:

.htaccess - htaccess 带空格的文件名损坏

regex - url 中存在空格的 mod 重写问题

mongodb - 使用 Perl 的 Mongodb 的 SSL 连接问题

java - 为 Web 服务启用 SSL "Mutual Authentication",为 GUI 启用 "One Way Authentication"?

ssl - 使用 TLS 从 Go 客户端进行 gRPC 调用 - GCP 云功能

javascript - 将文件夹中的所有文件重定向到另一个页面,但仍允许访问 html 文件

codeigniter - 仅为 url 重写路径设置 htaccess php_value

.htaccess - 一些未知的东西将它添加到我的 htaccess 中。怎么办?

django - 适用于付费测功机的 Heroku 免费 SSL 无法在 "old"应用程序上运行

python - 设置并验证 Python MySQL 连接中使用的 SSL/TLS 版本