Hiding or removing controller name in url using routes for seo purpose = codeigniter

前端 未结 2 1514
盖世英雄少女心
盖世英雄少女心 2021-01-23 10:48

I am using one controller. How can I remove or hide the controller name on my URL using routes? I already set my .htaccess to remove my index.php. I\'ve tried lots of code from

2条回答
  •  走了就别回头了
    2021-01-23 11:21

    Simple approach when i use CI:

    Example Controller:

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

    Example routes:

    //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';
    

    My 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]
    

    Access the uri:

    http://yoursite.com/check
    http://yoursite.com/choke/whatever
    
    //or
    
    http://yoursite.com/squirrel
    http://yoursite.com/woohoo/whatever
    

    Addition: Here is complete routes from my old project using CI, maybe you can get something.

    Notes :

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

    Good luck.

提交回复
热议问题