Forcing HTTPS on All Traffic and All Pages Forcing HTTPS on All Traffic and All Pages codeigniter codeigniter

Forcing HTTPS on All Traffic and All Pages


Your thinking was correct to solve the problem, but regex was NOT correct. We need NOT to match everything here, since whole URL itself we need to change to https hence .* will work while rewriting rule. Could you please try following, if you have any other Rules too then keep these rules at very first/starting of .htaccess file. In case RewriteCond %{HTTPS} !on doesn't work then change it to RewriteCond %{HTTPS} off. Please make sure you clear your cache of your browser before you test URLs.

RewriteEngine ONRewriteCond %{HTTPS} !onRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L]


With OP's shown .htaccess it could be as follows, its a simple copy/paste from OP's question + my rules combinations, since I am not sure what exactly OP is dealing with other rules(moreover that is outside of focus of the question too).

<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteCond %{HTTPS} !onRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L]RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^([\s\S]*)$ /index.php [L,B,QSA]</IfModule>


After installing an SSL certificate, your website is available over HTTP and HTTPS. However, it’s better to use only the latter because it encrypts and secures your website’s data.

you can see the full tutorial herehttps://tutsfx.com/force-https-traffic-using-htaccess/

Forcing HTTPS on All Traffic

RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

IMPORTANT: Make sure that the line RewriteEngine On is not repeated twice. In case the line already exists, simply copy the rest of the code without it.