简体   繁体   English

WordPress http 到 https 重定向

[英]Wordpress http to https redirection

I have a wordpress website with ssl implemented.我有一个实现了 ssl 的 wordpress 网站。 The website is working properly at https://domain.com .该网站在https://domain.com上正常运行。 I want to redirect all the traffic from http://domain.com to https://domain.com .我想将所有流量从http://domain.com重定向到https://domain.com I googled about this and changed my .htaccess to following:我用谷歌搜索了这个并将我的 .htaccess 更改为以下内容:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

The redirection is not working.重定向不起作用。 I have tried plugins like Easy HTTPS redirection, Wordpress HTTPS, etc but still it is not working.我尝试过 Easy HTTPS 重定向、Wordpress HTTPS 等插件,但仍然无法正常工作。 Can someone please help me out on this.有人可以帮我解决这个问题吗? Also i would like to add that when I try to visit http://domain.com it does not connect.我还想补充一点,当我尝试访问http://domain.com时,它无法连接。 Thanks in advance.提前致谢。

Make sure you have changed the settings in wp_options table, siteurl and home to include 确保已更改wp_options表,siteurl和home中的设置以包括

option_name                     option_value     
siteurl                         https://<your domain>
home                            https://<your domain>

要一切从流量重定向HTTP://.comHTTPS://.com我使用这个插件(作品总是对我来说): https://wordpress.org/plugins/wp-force-ssl/

You shoudn't need a plugin to do this... 您不需要插件即可执行此操作...

Try with this little change in your .htaccess 's RewriteRule: 尝试在.htaccess的RewriteRule中进行以下更改:

RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Try moving the RewriteBase below the http redirect and into the wordpress section. 尝试将RewriteBase移到http重定向下方并移到wordpress部分。 It solved my the issue for me. 它为我解决了我的问题。

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Make sure that you define the WP_SITEURL and WP_HOME at wp-config.php确保在 wp-config.php 中定义了 WP_SITEURL 和 WP_HOME

define('WP_HOME','https://yourdomain.com');
define('WP_SITEURL','https://yourdomain.com');

And add this condition to check if the https at wp-config.php并添加此条件以检查 https 是否位于 wp-config.php

 if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
    $_SERVER['HTTPS'] = 'on';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM