I’m new here and I’m still trying to figured it out stuff. I have the website hosted by UOLhost which supports Let’s Encrypt. I was trying to redirect HTTP to HTTPS adding the most simple code I could find to my .htaccess.
It didn’t work, and after some research I found out it was because of Let’s Encrypt. So I found another code that worked perfectly for about 2 days, but today it stopped working and I have no idea why. Did anything change from Let’s Encrypt side or is it something that my hosting changed?
Here is the code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Verify www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
# Verify POST requests
RewriteCond %{REQUEST_METHOD} !^POST$
# If receiving HTTP request from proxy...
RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
#...or if it's a resquest direct from client
RewriteCond %{HTTP:X-Forwarded-Proto} =""
RewriteCond %{HTTPS} !=on
# Redirect to HTTPS version
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
</IfModule>
Any ideas or a better code?
Operational System: Linux
Apache: version 2.4
PHP: version 5.5
Database: MySQL version 5.6
I remember having a similar problem with a hosting company that was using a caching reverse proxy. It turned out the cache wasn’t distinguishing between HTTP and HTTPS responses from the webserver (since they were both over HTTP at that point), and was caching them together - so sometimes a HTTPS request would be served a cached HTTP response, which was a redirect to HTTPS, and the result was an infinite redirect loop.
I fixed it by adding this line above my first RewriteCond:
Header always append Vary X-Forwarded-Proto
Of course you may be having an entirely different problem, but I guess it’s worth a shot,
If you click Advanced you should be able to get more info.
Are you sure you are having problems with redirecting, and not certificate problems? I ran a check of your site in SSL Labs. It says your certificate doesn’t match.
(abbreviated output)
SSL Report: www.coteseg.com
Certificate name mismatch
Try these other domain names (extracted from the certificates):
Thanks for your help @TheEggman but I’m a newbie on all this. What do you mean by config? The .htaccess? I don’t have anything at moment there. If not, where do I find this config?
I’m guessing this but I don’t think I have. I’m only accessing the FTP and some minor advanced configuration from the hosting control panel like clearing cache, changing versions of Apache and PHP, not much else.