.htaccess - 强制 WWW 使用 HTTPS

标签 .htaccess ssl https

我如何强制 www 使用 https 而不仅仅是 http?

例如访问http://www.example.com时它重定向到 https://www.example.com但如果您不包含 www,您就不会被重定向到 SSL 版本。

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.(.*)$
RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{REQUEST_URI} !^/crossdomain.xml
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

最佳答案

以下条件应该适用于 www 和没有它。

RewriteCond %{HTTP_HOST} ^(www\.)?example.com [NC]

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

相关文章:

wordpress 利用浏览器缓存

ssl - 等待从订单状态 "pending"发出证书

asp.net - 我的 Web 应用程序需要 SSL 吗?

python - 使用 ssl 模块的 HTTPS 代理隧道

java - 添加 URL.openStream 使用的证书

apache - .htaccess 重定向到新域

apache - 如何从 Apache URL 重写条件中排除子目录

php - .htaccess 不允许用户查看我的没有 index.php 的文件夹文件

asp.net - 使用 IIS Express 模拟 SSL 终止

ssl - ChromeDriver 仅打开具有有效 SSL 证书的网站