How to replace underscores in codeigniter url with dashes?

前端 未结 8 1257
有刺的猬
有刺的猬 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:22

    It really depends on your intention. If you just want to change only one page, then devrooms' solution is the perfect one indeed:

    $route['request-guide'] = "request_guide";
    

    But if you want to make this your website's default behavior you should extend your core Router class like this (source: [Using hyphens instead of underscores in CodeIgniter])

    1. Make a new file in 'application/core' and name it 'MY_Router.php'
    2. Insert this code in it:

      
      

    UPDATE (Oct 26, 2015): There's a better way to do this in CodeIgniter 3, as @Thomas Wood mentioned:

    $route['translate_uri_dashes'] = TRUE;
    

提交回复
热议问题