Search code examples
sslopencart-3

Opencart SLL httpaccess


I've got Opencart 3.0.2.0 installed on my webhosting which is in UK with 123-reg. The SSL seems to be installed correctly, because when I type in the full https included domain name, all sites secure. But if I only type in the domain name, never goes to the secure site. I've tried to change .httpaccess.txt but none of what I found worked. This is what I have now to force to load https:

# Force HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

Can someone please help me? What setting is I'm missing? Is it possible that the hosting company hasn't set up something correctly? Thank you


Solution

  • It sounds like you were trying to use opencart's htaccess file and not your domain's htaccess file. I had to re-read your originally post to figure this out finally. Please edit your domain's htacess file instead. If you don't have an htaccess file then you need to create one.

    This is typically what's used in the htaccess file of your domain (not opencart's htaccess). I used example.com for demonstrative purposes here, but replace it with your domain instead. This also assumes that you are keeping your OC installation/store in a subdirectory/folder (the best practice in general) and it's being accessed at www.example.com/store. Let me know if this works. In my case, it was also imperative to use the Options +FollowSymlinks at the top as you can see. But not sure if you need to as it can depend on the host you are using.

    To sort of explain better what you are seeing here, HTTPS uses a default port number of 443 and HTTP uses 80. So you're forcing port 80 to redirect to your HTTPS instead. The line involving "REQUEST_URI" points to your store directoy. Thus all files in the directory with be HTTPS. The last line also sets the page visitors will automatically be directed to when they type and go to "www.example.com" which will end up being www.example.com/store/index.php. If you do not have OC installed in a sub directory of your domain then you will need to adapt this to your needs then.

    Options +FollowSymlinks
    
    RewriteEngine on 
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
    RewriteCond %{REQUEST_URI} !^/store/ 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ /store/$1 
    RewriteCond %{HTTP_HOST} ^(www.)?example.com$ 
    RewriteRule ^(/)?$ store/index.php [L]