如何将所有内容路由到 codeigniter 中的默认控制器?

发布于 2025-01-07 05:19:37 字数 1130 浏览 0 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

习ぎ惯性依靠 2025-01-14 05:19:37

如果不存在 URI,则调用 $route['default_controller']。使用 $route['404_override'] 进行完整的“捕获所有”。

要让您的路由模式发挥作用,请尝试以下操作:

$route['[^/]*/(.*)'] = 'en/domain/view/$1';

$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:

$route['[^/]*/(.*)'] = 'en/domain/view/$1';
本宫微胖 2025-01-14 05:19:37

我通过这样做解决了我的问题

$route['^[a-z]+
] = 'domain/view/$1';
$route['([a-z]{2})/([a-z_]{1,50})'] = 'domain/view/$2';

I have managed my problem by doing this

$route['^[a-z]+
] = 'domain/view/$1';
$route['([a-z]{2})/([a-z_]{1,50})'] = 'domain/view/$2';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文