-1

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.

halfer
  • 18,701
  • 13
  • 79
  • 158

2 Answers2

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
  • 4,985
  • 5
  • 23
  • 25
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
  • 74
  • 1
  • 5
  • 1
    What "newer browsers" do you mean? Which "older browser" wouldn't work with it? – Niet the Dark Absol Jun 03 '17 at 14:15
  • 1
    Very 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