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

橙三吉。 提交于 2019-12-25 18:53:24

问题


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!


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/44344452/redirect-from-http-to-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!