在cpanel中将http站点url自动重定向到https
将站点url http重定向到https..为此,我在我的cpanl public_html根目录中上载.htaccess文件。该文件的代码为在cpanel中将http站点url自动重定向到https,http,ssl,https,ssl-certificate,cpanel,Http,Ssl,Https,Ssl Certificate,Cpanel,将站点url http重定向到https..为此,我在我的cpanl public_html根目录中上载.htaccess文件。该文件的代码为 RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://sitename.in/$1 [R,L] 在我托管此文件之后,它也不会将我的站点重定向到https协议我在站点的索引页中添加了以下代码行 if($_SERVER["HTTPS"] != "on") {
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://sitename.in/$1 [R,L]
在我托管此文件之后,它也不会将我的站点重定向到https协议我在站点的索引页中添加了以下代码行
if($_SERVER["HTTPS"] != "on")
{
header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
exit();
}
然后站点url重定向到https链接我刚刚修改了答案第一部分中的.htaccess文件,将我的Wordpress站点重定向到http://到https://。我不需要修改索引页,没有它,它对我来说很好。感谢这篇文章的作者,因为它完成了我对安全证书迁移的探索 我的完整文件.htaccess文件在我看来是这样的。我建议制作一份本地副本,因为我在这里找到了适合我的正确答案之前,曾多次破坏我的网站:
#RewriteCond %{HTTP_HOST} ^yoursite\.com [NC]
#RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
# 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]
</IfModule>
# END WordPress
Options +FollowSymlinks
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [R,L]
#RewriteCond%{HTTP_HOST}^yoursite\.com[NC]
#重写规则(.*)http://www.yoursite.com/$1[R=301,L]
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
选项+FollowSymlinks
重写cond%{SERVER_PORT}80
重写规则^(.*)$https://www.yoursite.com/$1[R,L]
我写这个答案太晚了,但目前还可以。因此,请尝试在根目录.htaccess文件上执行此操作
# Force SSL
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
#强制SSL
重新启动发动机
重写cond%{HTTPS}=关于[NC]
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[R=301,L]
注意:只有当您在cpanel服务器上安装了
mod_rewrite
时,它才会起作用,否则请使用基于php的SSL重定向。在.htaccess上使用cpanel安装Wordpress对我来说非常有用。谢谢