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
- How can I solve this problem with the
.htaccess
file in order to have a working HTTPS only website? - In the Wordpress admin area, in
Settings > General
, should I change the addresses fromhttp://www.example.com
tohttps://www.example.com
? And it should be done before or after modifying.htaccess
? - 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?
.htaccess
file? your.htaccess
already has rules for SSL. The cache may be affecting your HTML output already. – Jack Johansson♦ Feb 9 '17 at 22:25.htaccess
and then enable the cache. Try removing the code between lines 163 to 181 in your.htaccess
(the code in the pastebin), and see if it works. – Jack Johansson♦ Feb 10 '17 at 11:32