我有一个网页,如果用户来自http://,我想重定向到特定的链接。
<script language="JavaScript">
  var loc = window.location.href+'';
    if (loc.indexOf('http://')==0){
      window.location.href = loc.replace('http://','https://secure.example.com/app');
    }
</script>如果用户来自http://example.com/app或任何http://,则希望将其重定向到该链接。
当我运行这个JavaScript时,它使用https://secure.example.com/app并添加domain.com/app,如下所示
如果能对此提供任何帮助,我们将不胜感激。
我也尝试了元标签的东西<meta http-equiv="refresh" content="2;url=https://secure.example.com/app" />。
但它总是让人耳目一新,不太适应页面的变化。
发布于 2018-04-11 20:17:59
将此添加到服务器配置文件中,而不是在html中执行。
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]301重定向应该是更好的方法。
对于javascript方法(Es6)。不是推荐的方法,因为浏览器重定向并不总是可靠的。
 return location.protocol != 'https:' ? location.protocol = "https:" 
: {do nothing logic}https://stackoverflow.com/questions/49783729
复制相似问题