Force HTTPS Custom domain

I’m trying to make my domain always go to https, but even using cloudflare, it doesn’t redirect, it always sends me to a large url

Does anyone know how to fix it?

1 Like

Hey @DoginUwU,

Pasting this code in your server.js can also force HTTPS for your website:

function checkHttps(req, res, next){
  // protocol check, if http, redirect to https
  
  if(req.get('X-Forwarded-Proto').indexOf("https")!=-1){
    return next()
  } else {
    res.redirect('https://' + req.hostname + req.url);
  }
}

app.all('*', checkHttps);

Hope this helps!

He keeps redirecting me to the large URL :c

and always req.get('X-Forwarded-Proto') returns https

I would recommend using Cloudfare. You will have to change your current name servers to Cloudfare ones and once you have done that you can force encryption.

I was already using cloudflare, even with the option to force HTTPS active ;-;

Interesting. You did the setup correctly?

Yes, I’ve been messing with cloudflare for a long time, but this https never happened before

Hmm. Sorry I don’t know what to say!
It looks like everything is correct.

1 Like

I actually just visited your website I could not view it without HTTPS.

Try using http://anigiri.ga?lang=pt-br

It works when you don’t have the language parameter set

Yep, still gives me HTTPS.

HTTPS but at a large URL?

Screenshot 2020-03-16 at 5.06.56 PM

What?? Here he sends me to this URL

Thats odd.
Try view the project details of that page.
https://glitch.com/~(project url name here)

I didn’t find anything about this url. I have no more ideas than can be

The long is not a shw.io URL either, it’s just a Glitch project with a very long name…

When I refer to this, it is displayed in https://anigiri.ga/?lang=pt-br . It is working.

It seems to keep the old behavior because you have a cache in your browser.
Are you using Chrome? Check the operation in the Incognito Window:

Also, the settings in Cloudflare are currently here: (I also use Cloudflare!)
anigiri.ga(your domain) - SSL/TLS - Edge Certificates - Always Use HTTPS to “ON

2 Likes

I have the same issue but am unable to switch to cloudflare since the domain is used by others as well. The https redirection works on the .glitch.com url but not through the custom domain. Is it the case that the only way to get forced https when using a custom domain is using a tool within the custom domain’s DNS provider?

Sorry for the Necro… just realised it isn’t 2020 anymore :'o