如何设置 htaccess 从 http 转换到 https?

如何设置 htaccess 从 http 转换到 https?

这是我的 .htaccess - 网站确实重定向到 HTTPS,但仍然显示:您与网站的连接已加密,但 Google Chrome 已检测到页面上的混合内容。如何避免这种情况?谢谢。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
</IfModule>

答案1

除了上述两个人所说的内容之外,您可能还应该对您托管的任何内容使用相对链接:“src=images/banner.jpg”而不是“src=http://example.com/images/banner.jpg

任何场外资源(例如 jquery)都应通过 https 加载。

但是您看到的错误是因为您的页面上有通过 http 链接的资源(images/css/js)。mod_rewrite 将无法帮助解决此问题,因为初始连接仍然是加密的。

相关内容