From 2305ea4ed9f9ca56c9819fd1d4230688fe76468b Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Thu, 21 Dec 2017 12:03:56 +0530 Subject: [PATCH] Snippet to perform HTTPS redirect --- snippets/httpsRedirect.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 snippets/httpsRedirect.md diff --git a/snippets/httpsRedirect.md b/snippets/httpsRedirect.md new file mode 100644 index 000000000..f60a79610 --- /dev/null +++ b/snippets/httpsRedirect.md @@ -0,0 +1,9 @@ +### httpsRedirect + +Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history. + +```js +const httpsRedirect = () => { + if(location.protocol !== "https:") location.replace("https://" + location.href.split("//")[1]); +} +``` \ No newline at end of file