0

I'm working on an angular 1.5.0-rc0 project.

I'm using angular-route with ng-view with the following configuration:

  app.config(['$routeProvider','$locationProvider',
    function($routeProvider,$locationProvider) {
        $routeProvider.
        when('/',{
            templateUrl: 'views/index.html',
            controller: 'IndexController',
        }).
        when('/login', {
            templateUrl: 'views/login.html',
            controller: 'LoginController'
        }).
        when('/cocktail/:cocktail_name', {
            templateUrl: 'views/cocktail.html',
            controller: 'CocktailController',
        }).
        when('/add-drink',{
            templateUrl: 'views/add-drink.html',
            controller: 'AddDrinkController',
        }).
        when('/add-cocktail',{
            templateUrl: 'views/add-cocktail.html',
            controller: 'AddCocktailController',
            controllerAs: 'addCocktail'
        }).
        when('/admin-drinks',{
            templateUrl: 'views/admin-drinks.html',
            controller: 'AdminDrinksController',
            controllerAs: 'adminDrinks'
        }).
        when('/login',{
            templateUrl: 'views/login.html',
            controller: 'LoginController',
            controllerAs: 'login'
        }).
        otherwise({
            redirectTo: '/'
        });

I want to check if users are browsing using https or http. and in case they browse /login using http I want to redirect them to https.

how can i do that ?

ufk
  • 30,912
  • 70
  • 235
  • 386
  • 1
    If you are creating a Single Page Application, you may as well just make it all https, rather than only trying to redirect them if they go to /login - if you are only using Angular routing, once they have logged in they will remain on https anyway. Better to do this server-side as @GadgetBlaster says – Rhumborl Dec 15 '15 at 16:21

1 Answers1

1

I would do it server side before the site loads your JS. I have done this in an angular app in the past and it is more secure to do it in PHP or Apache. Here is a PHP example: Redirecting from HTTP to HTTPS with PHP

Community
  • 1
  • 1
Gadget Blaster
  • 759
  • 5
  • 15