简体   繁体   中英

Wordpress http to https redirection

I have a wordpress website with ssl implemented. The website is working properly at https://domain.com . I want to redirect all the traffic from http://domain.com to https://domain.com . I googled about this and changed my .htaccess to following:

<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. 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. Thanks in advance.

Make sure you have changed the settings in wp_options table, siteurl and home to include

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:

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. 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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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