php-使用路由为seo目的隐藏或删除url中的控制器名称= codeigniter

我正在使用一个控制器.如何使用路由删除或隐藏URL上的控制器名称?
我已经设置了.htaccess来删除index.php.我从其他类似的问题中尝试了很多代码,但是我没有运气.我不知道我的实时服务器是否有问题,因为在上一个项目中我使用了此代码

$route['del/(:any)'] = "my_cotroller";
$route['(:any)'] = 'pages/view/$1';

并且这很好用,但是当我尝试在当前项目中使用它时,它没有用.
这是我的默认路线

$route['default_controller'] = "my_cotroller";
$route['404_override'] = '';

我想存档一个像http://www.sample.com/login这样的URL,但是我当前的路由代码给了我这个http://www.sample.com/my_controller/login.

感谢帮助.

最佳答案
使用CI时的简单方法:

控制器示例:

<?php
class Haha extends CI_Controller
{
    public function check()
    {           
        $this->load->view('path/to/check/view');
    }

    public function choke()
    {
        $this->load->view('path/to/choke/view');
    }
}

路线示例:

//same name with C method
$route['check'] = 'haha/check';
$route['choke/(:any)'] = 'haha/choke';

//or custom route name
$route['squirrel'] = 'haha/check';
$route['woohoo/(:any)'] = 'haha/choke';

我的htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$./index.php/$1 [L]

访问uri:

http://yoursite.com/check
http://yoursite.com/choke/whatever

//or

http://yoursite.com/squirrel
http://yoursite.com/woohoo/whatever

加成:
这是我使用CI的旧项目的完整路线,也许您可​​以得到一些帮助.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$route['default_controller'] = 'sitehome';

$route['page'] = 'sitehome/page';
$route['page/who-we-are'] = 'site/whoweare';
$route['page/why-use-us'] = 'site/whyus';
$route['page/about-us'] = 'site/about';
$route['page/contact-us'] = 'site/contact';
$route['page/news'] = 'site/news/news';
$route['page/topics'] = 'site/topic';
$route['page/polls'] = 'site/polls';
$route['page/results'] = 'site/result';
$route['agent/detail/(:any)'] = 'site/agentdetail';
$route['register'] = 'site/register';
$route['login'] = 'site/login';

$route['user/home'] = 'usermain';
$route['user/edit-account'] = 'user/editaccount';
$route['user/retire'] = 'user/retired';
$route['user/business/data'] = 'user/business';
$route['user/business/topic/create'] = 'user/topic/topiccreate';
$route['user/business/topic/view'] = 'user/topic/topicview';
$route['user/business/topic/edit/(:num)'] = 'user/topic/topicedit';
$route['user/inbox'] = 'user/inbox';
$route['user/message/read/(:any)'] = 'user/readmessage';
$route['user/provider/list'] = 'user/providerlist';
$route['user/provider/send-message/(:any)'] = 'user/providerlist/sendmessage';
$route['user/notification'] = 'user/notified';
$route['user/inquiry'] = 'user/inquiry';

//testing purpose
$route['percobaan'] = 'coba/percobaan';

$route['poll'] = 'site/polls/retrievePoll';

//serve response
$route['response/single-poll'] = 'api/ResponseData/serveHomePoll';
$route['response/multi-poll'] = 'api/ResponseData/servePoll';

$route['404_override'] = 'notFound';
$route['translate_uri_dashes'] = FALSE;

/* End of file routes.php */
/* Location: ./application/config/routes.php */

注意事项:

http://example.com/business/ will fail or not exist.

祝好运.

转载注明原文:php-使用路由为seo目的隐藏或删除url中的控制器名称= codeigniter - 代码日志