Angularjs 重定向到 https



如何将http页面重定向到https?

我已经在login.config中尝试过这个代码块,但它转到http并导航到https。我想首先解决https。

    resolve: {
        data: function ($q, $state, $timeout, $location, $window) {
            var deferred = $q.defer();
                if ($location.protocol() !== 'https') {
                    $window.location.href = $location.absUrl().replace('http', 'https');
                }
                deferred.resolve(true);

            return deferred.promise;
        }
    }

谢谢

您应该使用网络服务器重定向到 https。

例如,如果您正在使用nginx

,请编辑nginx.conf的服务器部分

server {
       listen         80;
       server_name    my.domain.com;
       return         301 https://$server_name$request_uri;
}
server {
       listen         443 ssl;
       server_name    my.domain.com;
       # add Strict-Transport-Security to prevent man in the middle attacks
       add_header Strict-Transport-Security "max-age=31536000"; 
       [....]
}
我相信

你在错误的层面上解决了这个问题。您的AngularJS项目托管在某种服务器上(NodeJS,Apache HTTP,NGINX等(。此服务器应负责执行重定向!

对于Apache HTTP,你可能想看看: https://wiki.apache.org/httpd/RedirectSSL

在NGINX的情况下,你的配置中会有类似的东西:

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name _;
  return 301 https://$host$request_uri;
}

最新更新