Codeigniter-URI路由不工作


Codeigniter - URI Routes not working

我当前的URI是什么样子的:localhost/home/savedlocalhost/home/view

我想要它的样子:localhost/savedlocalhost/view

我的home控制器是什么样子的:

class Home extends CI_Controller
{
    public function index() {
        //stuff
    }
    public function saved() {
        //stuff
    } 
    public function view() {
        //stuff
    }
}

我想从URL中去掉home,这样用户就可以访问我家中的localhost/saved和其他功能,而无需在URL中键入home

我试着把这些放在routes.php文件中,但没有成功。

$route['home/(:any)'] = "$1";
//that didn't work so I tried putting this:
$route['home/(:any)'] = "/$1";
//that didn't work either.

非常感谢您的帮助。谢谢

试试这样的

$route['saved'] = 'home/saved';
$route['view'] = 'home/view';

输出-www.example.com/savedwww.example.com/view

组规则为:

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

在路由的末尾设置此规则,因为(:any)占位符是贪婪的,如果不是特定指向的,则会接受URL中的任何内容。意思是:如果你有方法为public function show($id){/*some code*/}的控制器Product.php,并且想要接近,那么路由应该指向上面的规则之前。

路由将按定义的顺序运行。较高的路线总是优先于较低的路线。

文档。