![](/img/trans.png)
[英]SSL Error: how to redirect https://www.domain.com to http://domain.com via .htaccess to avoid SSL error
[英]How to redirect http://domain.com to https://www.domain.com?
我已经获得了SSL证书。 我安装了Wordpress,请参阅我的hostgator文件管理器中的文件夹结构:
我已经把define('FORCE_SSL_ADMIN', true);
在wp_config.php
Wordpress常规设置:WordPress地址(URL): https : //www.domain.com/blog网站地址(URL): https : //www.domain.com
public_html
-> blog (inside is the wordpress installation)
database structure
-> wp_options
-> siteurl: https://www.domain.com/blog
-> home: https://www.domain.com
我尝试了hostgator cpanel重定向,但没有用。
在谷歌搜索时,我也尝试了一些编辑.htaccess
的解决方案。
也许我错过了关于文件夹结构的一些事情。
.htaccess
:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
您通常只需将规则添加到wordpress规则中。 他们在wp规则之前走了。
RewriteEngine On
#rewrite http to https and add www. All cases covered
RewriteCond %{HTTPS} !^on [OR]
RewriteRule %{HTTP_HOST} ^exmaple\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
您将需要2个虚拟主机,一个用于端口443(https),另一个用于端口80.在端口80中,您只需为所有流量设置重定向规则
<VirtualHost *:80>
...
RewriteEngine On
RewriteRule .* https://www.domain.com [R=301,L]
...
</VirtualHost>
使用
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
在所有条件下强制使用SSL(使用或不使用www
)。
此外,正如您所做的那样,在Wordpress常规设置中更改为https
。
不要在# BEGIN WordPress
和# END WordPress
重写块中添加强制SSL规则,因为如果您重新保存永久链接(甚至是插件),您的SSL规则将被删除。
然后使用Firefox (或Firebug )或Chrome或Safari或IE中的开发人员工具查看是否存在任何non-secure
元素错误,例如样式表和functions.php文件中的硬编码http://
URL。
这是我修复的最后一个度假胜地。 我在header.php中设置了一个php代码,用于检查输入的url是否为https,如果没有,则重定向到https的url。
<?php
if (empty($_SERVER['HTTPS'])) {
header('Location: https://domain.com');
exit;
}
?>
谢谢大家,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.