What is the right way to redirect all traffic to HTTPS?

Question

What I want to do

I manage a website on a hosting service that recently enabled the option to activate a free SSL certificate. I want to redirect all my traffic to the HTTPS version, and make it so that the plain HTTP version won’t be available anymore.

What I have tried

I have enabled the SSL certificate on the control panel, and tried to follow the procedure explained by the hosting service, that basically consists in adding some code to the .htaccess file, namely this one:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

My current .htaccess is already populated by the entries by WordPress itself and a couple of plugins, W3 Total Cache and Wordfence Security (here is a link to pastebin, sorry but I couldn’t get it properly formatted here).

I have appended the code from the hosting company to the end of the file, but it didn’t work properly and as a result the webpages were badly rendered and the URL itself was modified with random code. I don’t know if it was a redirect loop, a conflict with the minification of W3TC, or a combination of both.
What I can guess after a bit of code review is that in the the .htaccess file there are various entries with the <IfModule mod_rewrite.c> condition, that probably generate conflicts.

What I need to know

  1. How can I solve this problem with the .htaccess file in order to have a working HTTPS only website?
  2. In the WordPress admin area, in Settings > General, should I change the addresses from http://www.example.com to https://www.example.com? And it should be done before or after modifying .htaccess?
  3. Is it necessary to both modify .htaccess and the addresses, or they do the same thing and I should apply only one of these things?

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/what-is-the-right-way-to-redirect-all-traffic-to-https/">

What is the right way to redirect all traffic to HTTPS?</a>
0
, , , Sekhemty 6 months 0 Answers 44 views 0

Leave an answer