g.dlta
g.dlta

Reputation: 63

Forcing HTTPS on All Traffic and All Pages

I have a Codeigniter application which was developed and tested on the normal http. We recently moved to SSL certificate and all page the website doesn't redirect properly in .htaccess.it done only for front page http://grdagrd.com/. but it does not work for other pages: Sonbol Roud dam

How Forcing HTTPS on All Traffic and All Pages for base url https://grdagrd.com/?

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

Upvotes: 3

Views: 1003

Answers (2)

flutterbloc
flutterbloc

Reputation: 1

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 here https://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.

Upvotes: 0

RavinderSingh13
RavinderSingh13

Reputation: 133518

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 ON
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ 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 On
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ /index.php [L,B,QSA]
</IfModule>

Upvotes: 3

Related Questions