0

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.

XCEPTION
  • 1,671
  • 1
  • 18
  • 38
  • Possible duplicate of [Recommended way to to redirect HTTP requests to HTTPS](http://stackoverflow.com/questions/37002582/recommended-way-to-to-redirect-http-requests-to-https) – Tom May 06 '16 at 11:28

5 Answers5

1

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]
Jordi Nebot
  • 3,355
  • 3
  • 27
  • 56
  • Actually I have tried this and came across that after implementing ssl my url at http itself is not working. Hence the redirection is not being carried out from the .htaccess file. What can be the cause of this? How can I debug ? – XCEPTION May 06 '16 at 10:57
  • Have you tried with `RewriteRule ^.*$ …`? Anyway, debugging `.htaccess` isn't an easy thing... Read [this tips](http://stackoverflow.com/questions/9153262/tips-for-debugging-htaccess-rewrite-rules) – Jordi Nebot May 06 '16 at 11:14
1

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>
Margach Chris
  • 1,404
  • 12
  • 20
1

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';
}
0

To redirect all the traffic from http://.com to https://.com i use this plugin ( works always for me): https://wordpress.org/plugins/wp-force-ssl/

Alex Belov
  • 61
  • 4
0

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>