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!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
This question already has answers here:
Closed 2 years ago.
回答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 [...]