2016-02-17 59 views
0

如何將http頁面重定向到https?Angularjs重定向到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; 
     } 
    } 

感謝

回答

1

你應該使用Web服務器重定向到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"; 

     [....] 
} 
1

我相信你在錯誤的層面解決問題您的服務器部分。您的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; 
}