0

我有一个 codeigniter 网站,其中请求 url 采用以下形式:

example.com/segment1/segment2/segment3 where:

segment 1 is a folder name
segment 2 is a controller name
segment 3 is a function name

我想将这些请求重新映射到:

example.com/segment2/segment3

我已经在我的 *routes.php* 配置中尝试过这个:

$route['(:any)/(:any)/(:any)'] = "$2/$3/$1";

我的浏览器地址栏中显示的请求没有改变:

example.com/segment1/segment2/segment3

我怎样才能解决这个问题?

4

2 回答 2

1

You can add this to your .htaccess file (as you mentioned your folder is static):

RewriteRule ^(.*)?/(.*)?$   your-folder-here/$1/$2   [L,NC]                                                 
于 2013-05-27T03:51:42.843 回答
0

这会起作用,但这会覆盖所有可能的 URL。

$route['(:any)/(:any)'] = 'controller_name/$1/$2';

为了使其他控制器工作,你必须在上面的语句之前定义

$route['other_controller_1/(:any)'] = 'other_controller_1/$1';
$route['other_controller_2/(:any)'] = 'other_controller_2/$1';

URI 路由:Codeigniter 用户指南

于 2013-05-27T05:00:51.443 回答