3

I'm using Magento 2.3.1, I have let's encrypt SSL installed, I want to force HTTPS in the admin area and the storefront end

in the admin panel, I go to

Stores > Configuration > General > Web

I put yet to "Use Secure URLs on Storefront" and yes to "Use Secure URLs in Admin"

That only enforces https in the admin area. I modifying .htaccess

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

That doesn't work, I can't really play with apache that much, because I might break varnish which doesn't play well with HTTPS, tried that.

Is there an easy way to enforce HTTPS?

1
  • Guys silly question I made a mistake and enable without the certs ready, I want to disable and use http back I tried [bin]$ /www/server/php/82/bin/php magento setup:store-config:set --base-url="myip:892/admin_m1wky7" --use-secure=0 --use-secure-admin=0 [bin]$ /www/server/php/82/bin/php magento cache:flush but it doesnt work
    – Vidanez
    Commented Mar 8 at 16:18

5 Answers 5

7

to force HTTPS, change your base url to https:// for unsecure too:

bin/magento setup:store-config:set --base-url="https://myshop.com/" --base-url-secure="https://myshop.com/" --use-secure=1 --use-secure-admin=1
bin/magento cache:flush

also if you have some redirect issues, you can add this to apache or .htaccess config:

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_METHOD} !=POST
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
1
  • the .htaccess solution was spot on, even better than my answer which was hit and miss. your answer is the recommended one.
    – Lynob
    Commented Jun 27, 2019 at 18:06
2

Go to

stores > configuration > general > web

Put yet to "Use Secure URLs on Storefront" and yes to "Use Secure URLs in Admin", as you did before

Also put yet to "Enable HTTP Strict Transport Security (HSTS)"

0

here you go:

bin/magento setup:store-config:set --base-url="https://domain.com/" --base-url-secure="https://domain.com/" --use-secure=1 --use-secure-admin=1 bin/magento cache:flush

1
  • Isn't this basically just the answer from 2019? Commented Mar 11 at 16:05
0

In my case I've solved the problem by running these 2 commands:

sudo bin/magento setup:store-config:set --base-url="https://YOUR-DOMAIN-HERE/" --base-url-secure="https://YOUR-DOMAIN-HERE/" --use-secure=1 --use-secure-admin=1

sudo bin/magento c:f

Note: replace the placeholder YOUR-DOMAIN-HERE by your custom domain name.

0

It seems an issue with the Magento application rather than the Helm chart itself. I have found an answer that may solve your issue: https://magento.stackexchange.com/a/38251

Add these lines to the end of your .htaccess and it should be fine:

# Detect the Load-Balancer-Header and set the header magento expects 
SetEnvIf X-Forwarded-Proto https HTTPS=on 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.