[英]How to redirect http://domain.com to https://www.domain.com?
I already got an SSL certificate. 我已经获得了SSL证书。 I got Wordpress installed see folder structure in my hostgator file manager below:
我安装了Wordpress,请参阅我的hostgator文件管理器中的文件夹结构:
I already put define('FORCE_SSL_ADMIN', true);
我已经把
define('FORCE_SSL_ADMIN', true);
in wp_config.php
在
wp_config.php
Wordpress General settings: WordPress Address (URL): https://www.domain.com/blog Site Address (URL): https://www.domain.com 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
I tried hostgator cpanel redirects, but not works. 我尝试了hostgator cpanel重定向,但没有用。
I also tried some of the solutions editing .htaccess
while searching in google. 在谷歌搜索时,我也尝试了一些编辑
.htaccess
的解决方案。
Maybe I missed on something regarding with the folder structure. 也许我错过了关于文件夹结构的一些事情。
.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
You typically just add the rules to your wordpress rules. 您通常只需将规则添加到wordpress规则中。 They go before wp rules.
他们在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
You will need 2 virtual hosts, one for port 443 (https) and one for port 80. In the port 80 you could simply setup a redirect rule for all traffic 您将需要2个虚拟主机,一个用于端口443(https),另一个用于端口80.在端口80中,您只需为所有流量设置重定向规则
<VirtualHost *:80>
...
RewriteEngine On
RewriteRule .* https://www.domain.com [R=301,L]
...
</VirtualHost>
Use 使用
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]
to force SSL on all conditions (with or without the www
). 在所有条件下强制使用SSL(使用或不使用
www
)。
Also, as you have done, change to https
in Wordpress General settings. 此外,正如您所做的那样,在Wordpress常规设置中更改为
https
。
Do not add the force SSL rule inside the # BEGIN WordPress
and # END WordPress
rewrite block, becuase if you ever resave permalinks (or even a plugin does) your SSL rules will be deleted. 不要在
# BEGIN WordPress
和# END WordPress
重写块中添加强制SSL规则,因为如果您重新保存永久链接(甚至是插件),您的SSL规则将被删除。
And then use the developer tools in Firefox (or Firebug ) or Chrome or Safari or IE to see if you have any non-secure
element errors, such as from hardcoded http://
URLs in stylesheets and functions.php files. 然后使用Firefox (或Firebug )或Chrome或Safari或IE中的开发人员工具查看是否存在任何
non-secure
元素错误,例如样式表和functions.php文件中的硬编码http://
URL。
This is my last resorts for the fix. 这是我修复的最后一个度假胜地。 I put up a php code in the header.php that checks if the inputted url is https if not then it redirects to the url with https.
我在header.php中设置了一个php代码,用于检查输入的url是否为https,如果没有,则重定向到https的url。
<?php
if (empty($_SERVER['HTTPS'])) {
header('Location: https://domain.com');
exit;
}
?>
Thanks all, 谢谢大家,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.