4
votes

I try to use Codeigniter with AngularJS routing, and it's working, but I need without hash. I use this code:

.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(true);
    $routeProvider.
        when('/', { templateUrl: 'assets/js/partials/blank.html' }).
        when('/:name', { templateUrl: 'assets/js/partials/blank.html', controller: PagesController }).
        otherwise({redirectTo: '/'});
}]);

but when I refresh the page, jumps to 404.

1
In order it to work in HTML5 mode, you need to setup your webserver (.htaccess) to respond with index page for all requests (non-status resourses).dfsq
Could you explain a bit precisely? I tried with this .htaccess, but always causes 404. code<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !index RewriteRule (.*) index.php [L] </IfModule>codelevipadre
Thank you for your effort. I finally figured out. The htaccess was good, just I had to change the route of 404 page within codeigniter. routes.php: $route['default_controller'] = "project_name"; $route['404_override'] = 'project_name'; Thank you!levipadre
Unfortunately not the perfect. When I type a page, which is not exists code($routeProvider.when('/:name',code...etc, I have infinite loop, Any idea?levipadre

1 Answers

5
votes

You can always set the $route['404_override'] = '' to you default controller. This way it will not be 404.