satya
satya

Reputation: 3560

Not getting JS/CSS filelinks while reloading the page using Angular.js and .htaccess

I am getting some link failure error while reloading the page using Angular.js and .htaccess. Actually i was trying to remove hash tag in angular.js. I set .htaccess file and set the base href . I am explaining my code below.

.htaccess:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /Gofasto/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !.*\.(css|js|html|png|jpg|jpeg|gif|txt)
    RewriteRule (.*) index.html [L]
</IfModule>

loginRoute.js:

var Admin=angular.module('Channabasavashwara',['ui.router']);
Admin.config(function($stateProvider, $urlRouterProvider,$locationProvider) {
    $urlRouterProvider.otherwise('/');
    $stateProvider
     .state('/', {
            url: '/',
            templateUrl: 'dashboardview/login.html',
            controller: 'loginController'
        })
        .state('dashboard', {
            url: '/dashboard',
            templateUrl: 'dashboardview/dashboard.html',
            controller: 'dashboardController'
        })
        .state('dashboard.profile', {
        url: '/profile',
        templateUrl: 'dashboardview/profile.html',
        controller: 'profileController'
    })
    .state('dashboard.dept', {
        url: '/dept',
        templateUrl: 'dashboardview/dept.html',
        controller: 'deptController'
    })
    .state('dashboard.princpal', {
        url: '/princpal',
        templateUrl: 'dashboardview/princpal.html',
        controller: 'princpalController'
    })
    .state('dashboard.dept_head', {
        url: '/dept_head',
        templateUrl: 'dashboardview/depthead.html',
        controller: 'deptheadController'
    })
    $locationProvider.html5Mode({
      enabled: true,
      requireBase: true
    });

})

when i am in dashboard page its working fine.but when i am in profile page 1st time its working fine and when i am reloading this page again i am getting the following error.

failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/Gofasto/dashboard/controller/profileController.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/Gofasto/dashboard/controller/deptController.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/Gofasto/dashboard/controller/deptheadController.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/Gofasto/dashboard/js/newbill.js Failed to load resource: the server responded with a status of 404 (Not Found)
profile:118 Uncaught TypeError: $(...).chosen is not a function
http://localhost/Gofasto/dashboard/css/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/Gofasto/dashboard/css/style22.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/Gofasto/dashboard/css/plugins.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/Gofasto/dashboard/css/pace.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/Gofasto/dashboard/css/style.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost/Gofasto/dashboard/icons/font-awesome/css/font-awesome.min.css Failed to load resource: the server responded with a status of 404 (Not Found)

All my css and js folders are present inside Gofasto folder but it is showing the wrong link where 1st time it is coming properly.I also set <base href="/Gofasto/">in the index page.Please help me to resolve this error.

Upvotes: 0

Views: 125

Answers (1)

Nerdwood
Nerdwood

Reputation: 4022

Try using an absolute path when referring to the resources, eg:

<link rel="stylesheet" type="text/css" href="/Gofasto/css/style.css">

... or:

<link rel="stylesheet" type="text/css" href="/css/style.css">

... instead of:

<link rel="stylesheet" type="text/css" href="css/style.css">

Upvotes: 2

Related Questions