我有一个名为“profile”的 Controller ,用户配置文件的 URL 是 www.example.com/profile/user
我已经在路由文件中使用 codeigniter 的重新路由
$route['profile/(:any)'] = "profile/index";
我正在寻找的是从 URL 中删除配置文件 Controller 名称,以便它对 SEO 和用户友好。
例如
www.example.com/user
有什么建议吗?
最佳答案
你可以尝试其中任何一种
// url could be yourdomain/imran
$route['(:any)'] = 'profile/index/$1';
// url could be yourdomain/10
$route['(:num)'] = 'profile/index/$1';
// url could be yourdomain/imran10
$route['([a-zA-Z0-9]+)'] = "profile/index/$1";
你的类可能看起来像这样
class Profile extends CI_Controller {
public function index($id)
{
// $id is your param
}
}
更新:(小心)
请记住,如果你有一个类 Someclass
并且你使用 url
就像 yourdomain/Someclass
那么这将被路由到 profile/index/$1
如果你有 $route['(:any)']
或 $route['([a-zA-Z0-9]+)' ]
。
关于php - 如何从 codeigniter 的 URL 中删除 Controller 名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19786855/