1

这个问题已被问过几次,但我似乎找不到对我有帮助的解决方案,这就是我在这里尝试的原因。

我为使用 CodeIgniter 的 URL 设置了以下站点我有一个名为 user 的控制器,它加载用户视图。

所以我的网址结构如下:

http://example.com/user/#/用户名

我想尝试从 URL 中删除用户控制器来整理我的 URL,这样他们就可以阅读:

http://example.com/#/用户名

这可能是我一直在寻找路线并尝试了很多不同的选择但没有一个奏效吗?

$route['/'] = "user";

谁能提供任何解决方案?

4

1 回答 1

2

Assuming the '#' in your URLs is a valid function and 'username' is a parameter for that function, then this route should work:

$route['#/(:any)'] = "user/#/$1";

Depending on what usernames are to be routed you may want to change the wildcard. For example, if you only wanted to route numbers as the parameter, you could change (:any) to (:num).

(:num) will match a segment containing only numbers.

(:any) will match a segment containing any character.

You can also use regular expressions to define routing rules, allowing you to further restrict what is routed.

于 2013-08-20T19:37:54.360 回答