Update httpsRedirect.md

This commit is contained in:
Arjun Mahishi
2017-12-21 16:10:50 +05:30
committed by GitHub
parent 2305ea4ed9
commit 0c86d71a4c

View File

@ -2,8 +2,10 @@
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. 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.
Use `location.protocol` to get the protocol currently being used. If it's not HTTPS, use `location.replace()` to replace the existing page with the HTTPS version of the page. Use `location.href` to get the full address, split it with `String.split()` and remove the protocol part of the URL.
```js ```js
const httpsRedirect = () => { const httpsRedirect = () => {
if(location.protocol !== "https:") location.replace("https://" + location.href.split("//")[1]); if(location.protocol !== "https:") location.replace("https://" + location.href.split("//")[1]);
} }
``` ```