I am trying to force https with my .htaccess file but when I do, the layout breaks and I get 404 errors in console for pretty much everything from css files to js files etc. I am using a MVC structure.
In my config file I have:
define('URLROOT', 'https://www.example.com');
In my header all my css files are called like this:
<link href="<?php echo URLROOT; ?>/css/style.css" rel="stylesheet">
My .htaccess looks like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
</IfModule>
Also, If I type in https://example.com it goes to https but if I just type in example.com it defaults to http which is also a problem.
2
Answers
Move your
http -> https
rule on top:Make sure to test in a new browser to avoid old browser cache.
Place this on top of your .htaccess, make sure to change the domain name and you are set – all HTTP requests (even those to static files) will get redirected to HTTPS: