Redirect from http:// to https:// [duplicate]

2020-01-19 06:14发布

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,any help would be appreciated!

2条回答
一纸荒年 Trace。
2楼-- · 2020-01-19 06:54

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 [...]

查看更多
相关推荐>>
3楼-- · 2020-01-19 06:58

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

查看更多
登录 后发表回答