Search code examples
codeignitercodeigniter-urlcodeigniter-routing

how to make url as pretty url in codeigniter


I am new to ci. naybody knows how to minify the url. for example : yourdmain.com/blog/view/blog-title I need this url to be like this : yourdmain.com/blog-title please explain how to do this this can be many like blog, categories, pages, posts please help..


Solution

  • Use route.php under your config folder

     $route['blog-title] = 'blog/view/blog-title';
    

    if you need dynamically loading based on a title

      $route['(:any)/index.html'] = 'blog/view/$1';
    
       // will route any url with /index.html to your controller
    
     $route['(:any).html'] = 'blog/view/$1';
    
     // will route any url with title.html to your controller then pass your title as your function variable
    

    Why index.html or .html

    This is my way i use to distinguish my other urls to my blog titles urls .. meaning only urls with extension index.html or .html will be routed to my blog/view path