4

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.

4
  • 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). Commented Feb 6, 2015 at 20:41
  • 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>code Commented Feb 6, 2015 at 20:57
  • 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! Commented Feb 6, 2015 at 21:23
  • 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? Commented Feb 7, 2015 at 1:07

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.