1

Our Magento 2 is setup with https on all pages (unsecure and secure, "use secure on frontend", etc.).

However sometimes when I enter ourdomain.com it redirects (correctly) to https and sometimes it remains http

How can I force that every single time ourdomain.com will redirect to https?

This is very important for SEO (otherwise Google will think they are two separate pages - http://ourdomain.com and https://ourdomain.com - and will think it is duplicate content).

I have tried flushing and cleaning the cache. I have reindexed.

I have even tested this with 301 redirect programs and they do not register a redirect from http to https (they just show 200 OK for http).

I am using Magento 2.2.5. Varnish is enabled and Pound gets the https pages (ssl termination; via.

Please help

1

The issue was the Pound was only listening to 443 (https) and all HTTP was going straight to Varnish. Magento was supposed to be redirecting but sometimes Varnish would just send the HTTP version.

The solution was to get Varnish itself to handle the http->https redirect. The way this was done is by editing the varnish vcl file as follows:

sub vcl_recv {
    if (req.http.X-Forwarded-Proto !~ "https") {
        set req.http.location = "https://" + req.http.host + req.url;
        return (synth(750, "Permanently moved"));
    }

/* rest of vcl_recv goes here */
}

sub vcl_synth {
    if (resp.status == 750) {
        set resp.http.location = req.http.location;
        set resp.status = 301;
        return (deliver);
    }
}

Credit for this Varnish edit goes to "meadowlandsview" (here in one of the comments).

Now Varnish redirects every single time.

I hope this can be of some help to someone. Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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