I want to redirect users from my http website to https site is there like a meta or JavaScript or html to do this my site has a http server as well as a secure version.
Asked
Active
Viewed 8,093 times
-1
-
1Redirects are best done at the HTTP level. How you implement them depends on your HTTP server and/or choice of server side programming language. – Quentin Jun 03 '17 at 13:31
-
1I liked both answers but Javascript was better for me , thank you. – Universal Omega Jun 03 '17 at 13:46
2 Answers
6
As a quick-fix you can do it like this:
if(window.location.protocol != 'https:') {
location.href = location.href.replace("http://", "https://");
}
But I recommend you to do it using the available method in your web server

yeradis
- 5,235
- 5
- 25
- 26
0
From https://stackoverflow.com/a/5411601/5031164
You should use html meta tag for newer browsers AND a javascript script for the older one, at the same time:
<meta http-equiv="refresh" content="0; url=https://example.com/" />
<script type="text/javascript">
window.location.href = "https://example.com"
</script>
I also report:
For completeness, I think the best way, if possible, is to use server redirects, so send a 301 status code [...]

lunix15
- 84
- 1
- 6
-
1What "newer browsers" do you mean? Which "older browser" wouldn't work with it? – Niet the Dark Absol Jun 03 '17 at 14:15
-
1Very old browser like till IE6 could have problem ( [read more here](https://en.wikipedia.org/wiki/Meta_refresh) ). Anyway I read that browsers could ignore 0 value meta refresh in few circumstances, so I suggest to keep the js script as well. [more here](https://stackoverflow.com/questions/5411538/redirect-from-an-html-page/5411601#5411601) – lunix15 Jun 03 '17 at 14:28