簡體   English   中英

AngularJS重定向到https

[英]Angularjs redirect to 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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM