0

I am building my first angularjs app in 1.6x and my router is resulting in a 404 errors

my router looks like this:

app.config(function($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(true);
    $routeProvider
    .when('/account', {
        templateUrl: 'views/account/welcome.html',
    }) //works
    .when('/account/emails', {
        templateUrl: 'views/account/email.html', 
        controller: 'emailController'
    }) //404 error
    .when('/account/wallet', {
        templateUrl: 'views/account/wallet.html',
    }) //404 error
    .when('/account/settings', {
        templateUrl: 'views/account/settings.html',
    }) //404 error
    .when('/account/logout', {
        templateUrl: 'views/account/logout.html',
    }) //404 error
    .otherwise({
        redirectTo: '/'
    }) //works
});

and my htaccess looks like this:

Options +FollowSymLinks

<ifModule mod_rewrite.c>

    RewriteEngine On 
    Options FollowSymLinks
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /#/$1 [L]

</ifModule>

So my router works correctly within the app, but if my browser address is at say //localhost/account/emailsor a similar path and I refresh the page, I get a 404 error. This also happens when I address the path directly from the browser.

//localhost/ and //localhost/account work because the are actual paths in the apps file system with respective index.html files. What am I doing wrong here?

Martin Adámek
  • 16,771
  • 5
  • 45
  • 64
Sandra Willford
  • 3,459
  • 11
  • 49
  • 96

1 Answers1

0

You have wrong RewriteRule in your .htaccess. You want to use HTML5 mode, so your URLs will not be prefixed with /#/ anymore.

This could work:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteCond %{REQUEST_URI} !^/account.*$
RewriteRule ^(.*) /account/index.html [NC,L]

RewriteRule ^(.*) /index.html [NC,L]
Martin Adámek
  • 16,771
  • 5
  • 45
  • 64