.htaccess - 如何将我的博客 http ://subdomain. example.com 重定向到 https://

标签 .htaccess http ssl redirect https

用于将我的子域 http: 重定向到 https:

我在 .htaccess 文件中使用了下面的代码,但没有用。

RewriteEngine on

RewriteCond %{HTTP_HOST}  ^subdomain\.example\.com$ [NC]
RewriteRule ^$ https://subdomain.example.com/ [R=301,NE,NC,L]

此外,我已经将 WordPress 站点 URL 中的 http 更改为 https,但仍然无法正常工作。

请指导我如何修复它。

最佳答案

RewriteCond %{HTTP_HOST}  ^subdomain\.example\.com$ [NC]
RewriteRule ^$ https://subdomain.example.com/ [R=301,NE,NC,L]

这只是检查主机,而不是 SSL 状态(即 HTTP 或 HTTPS)。这也只会重定向站点根目录,并会导致重定向循环。

请尝试以下操作。这将需要在 .htaccess 中的现有 (WordPress) 指令之前:

RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,NE,L]

测试前您需要清除浏览器缓存。

关于.htaccess - 如何将我的博客 http ://subdomain. example.com 重定向到 https://,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45279220/

相关文章:

html - <a href> 将链接附加到当前 url 的末尾

.htaccess - 使用 htaccess 将网站重定向到移动版网站

php - .htaccess 使用 .htpasswd 和 wordpress 请求正确登录两次

android - 如何从 Google Assistant 发出局域网 HTTP 请求?

performance - 在 https 中运行您的完整网站有什么缺点吗?

mysql - 使用 SSL pem key 连接到 AWS RDS 上的 MySQL

apache - 请求/而不是/index.php时获取 "authentication required"

javascript - 发送带有 JSON 正文的文件

php - 处理太多 mysql 连接的最佳实践

ubuntu - 使端口 443 免费