How to replace underscores in codeigniter url with dashes?

前端 未结 8 1239
有刺的猬
有刺的猬 2021-01-30 09:28

I would like to know the simplest solution to changing the underscores of my codeigniter urls to dashes, for seo reasons.

My controllers look like:

publi         


        
8条回答
  •  失恋的感觉
    2021-01-30 10:21

    You can use this _remap() method to handle such behavior. Place this method in your controllers or create a core controller and place it in.

    public function _remap($method, $params = array()){
        if(method_exists($this, $method)){
            return call_user_func_array(array($this, $method), $params);
        }else{
            $method = str_replace("-", "_", $method);
            if(method_exists($this, $method)){
                return call_user_func_array(array($this, $method), $params);
            }
        }
        show_404();
    }
    

提交回复
热议问题