Redirect http to https express.js

前端 未结 6 1990
-上瘾入骨i
-上瘾入骨i 2020-12-19 16:56

I\'m trying to reroute http (80) to https (443) in my express app. I\'m using some middle ware to do this. If i go to my https://my-example-

6条回答
  •  温柔的废话
    2020-12-19 17:06

    I'm using a similar solution, where I also prepend 'www' because our SSL certificate is not valid without it. Works fine in every browser, but Firefox. Any idea?

    http.createServer(function(req, res) {
      res.writeHead(301, {
        Location: "https://www." + req.headers["host"].replace("www.", "") + req.url
      });
      res.end();
    }).listen(80);
    

提交回复
热议问题