Page 1 of 1

Force store to https and www

Posted: Thu Jul 12, 2018 9:40 pm
by vaidyamanishjoshi
I am using opencart 3.0.2.0

My store is installed in a folder. e.g. www.myrootdomain.com/eshop

In my root domain htaccess, I have added following code to force www and to force https, But it is not working for /eshop

e.g.
if user types myrootdomain.com, he get redirected to https://www.myrootdomain.com

but if he types url for shop directly like myrootdomain.com/eshop, he is expected to redirect https://www.myrootdomain.com/eshop
but it is not working


code in htaccess in root folder is as follow :

Code: Select all

RewriteEngine on
#Force www:

RewriteCond %{HTTP_HOST} ^myrootdomain.com [NC]
RewriteRule ^(.*)$ https://www.myrootdomain.com/$1 [L,R=301,NC]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.myrootdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.myrootdomain.com/$1 [L,R=301]

Re: Force store to https and www

Posted: Thu Jul 12, 2018 10:05 pm
by Qphoria
I use this

Code: Select all

RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
You can just use it as is on any site because you don't need to hardcode the actual domain name. HTTP_HOST is a variable.