带有codeigniter的ui-router在刷新页面或用html5mode粘贴URL时给出404(true)

时间:2016-02-18 15:07:54

标签: javascript php angularjs codeigniter angular-ui-router

我在this seed project中使用了与angular-js和ui-router一样的codeiginiter,我想从网址中删除/#/,所以我使用了:

$urlRouterProvider.otherwise('/'); $locationProvider.html5Mode(true); 在我的app.js .config中,我还在<base href="/">上添加了index.php

现在我在网址上没有/#/但是当我刷新页面时,我得到了404,如果我复制了一个工作网址(我从主视图中看到它)并将其粘贴到URL行我也收到404消息。

我已经看过this question,但我不想覆盖我的404,我不认为这是明智的。

和想法?

1 个答案:

答案 0 :(得分:2)

感谢xkcd149this answer的链接,我发现更改codeiginiter 3中的路由以便始终通过CI根控制器应该如下所示:

on /application/config/routes.php

$route['default_controller'] = 'home'; //can have any name you want
$route['exampleUrl'] = 'home';
$route['anotherUrl/(:any)'] = 'home'; //this url passes a parameter
$route['anotherUrl/(:any)/(:any)'] = 'home'; //this one passes 2 parameters

希望这有助于某人。