如何将所有内容路由到 codeigniter 中的默认控制器?
我有一个使用 codeigniter 2 构建的网站 http://example.com 。默认控制器是
$route['default_controller'] = "domain";
如果我尝试要访问 pageX,链接应为 http://example.com/en/domain/view/pageX
。
我想允许网站的访问者通过键入
来访问此页面
http://example.com/pageX
我已经尝试过
$route['(:any)'] = "view/$1"; ==> it gives 404 Page Not Found
$route['(:any)'] = "domain/view/$1"; ==> it redirects to homepage with link shown as http://example.com/en/pageX
$route['(:any)'] = "en/domain/view/$1"; ==> it gives 404 Page Not Found
,但没有一个对我有用。
编辑
,添加以下内容:
$route['(:any)'] = 'domain/view/$1';
$route['en/blog'] = 'domain/view/blog';
example.com/blog
就可以正常工作 但我需要它更通用,以覆盖除管理页面之外的所有页面,如下所示:
$route['(:any)'] = 'domain/view/$1';
$route['^(?!admin).*'] = 'domain/view/$o';
//The above routes will show the home page only for whatever i try!!
我必须添加到routes.php
的路线是什么?
I have a website http://example.com built using codeigniter 2. the default controller is
$route['default_controller'] = "domain";
If I try to access pageX, the link should be http://example.com/en/domain/view/pageX
.
I want to allow the visitor of the website to access this page by typing
http://example.com/pageX
I have tried
$route['(:any)'] = "view/$1"; ==> it gives 404 Page Not Found
$route['(:any)'] = "domain/view/$1"; ==> it redirects to homepage with link shown as http://example.com/en/pageX
$route['(:any)'] = "en/domain/view/$1"; ==> it gives 404 Page Not Found
but non of them worked for me.
EDIT
by adding this:
$route['(:any)'] = 'domain/view/$1';
$route['en/blog'] = 'domain/view/blog';
example.com/blog
will work fine
but I need it to be more general to cover all pages except admin page, something like this:
$route['(:any)'] = 'domain/view/$1';
$route['^(?!admin).*'] = 'domain/view/$o';
//The above routes will show the home page only for whatever i try!!
What is the route that i have to add to routes.php
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不存在 URI,则调用
$route['default_controller']
。使用$route['404_override']
进行完整的“捕获所有”。要让您的路由模式发挥作用,请尝试以下操作:
$route['default_controller']
is invoked if there is no URI present. Use$route['404_override']
for a full "catch all."To get your routing pattern working, try this:
我通过这样做解决了我的问题
I have managed my problem by doing this