How can i redirect http page to https ?
I have tried this code block in login.config, but it goes to http and navigate to https. I want to resolve https firstly.
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;
}
}
Thanks
You should redirect to https using webserver.
For example, if you're using nginx edit your server section of 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";
[....]
}
I believe you are tackling the problem on the wrong level. Your AngularJS project is hosted on some kind of server (NodeJS, Apache HTTP, NGINX, whatever). This server should take care of doing the redirect!
For Apache HTTP, you might want to take a look at: https://wiki.apache.org/httpd/RedirectSSL
In case of NGINX, you would have something like that in your config:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.