URI routing in encoder

I have a CI site working well, except that the url is a little ugly. Which approach should I use to allow me to route what is displayed:

http://domain.com/content/index/6/Planning

to url:

http://domain.com/Planning

I am confused if this needs to be done in the routes file or in my .htaccess

thanks

+2


a source to share


2 answers


There are several ways to customize config / routes.php, the suitability depends on your requirements.



  • Route for each page if you only have a couple of pages you want to redirect:

    $route['Planning'] = 'content/index/6';  
    $route['Working'] = 'content/index/7';  
    // etc.
    
          

  • You can use a fallback URL that will match all other route rules - this means that you have to establish rules that could match this rule before the return rule. This also means that you have lost the ID and must query the database based on the header:

    $route['register'] = 'register'; // this would match the fallback rule  
    $route['([a-z-A-Z1-9_]+)'] = 'content/index/$1'; // letters, numbers and underscore  
    // you'll receive "Planning" as parameter to Content::index method
    
          

  • Or you can have a policy that all URLs must start with a capital letter, in which case you don't need to worry about other route rules.

    $route['([A-Z]{1}[a-z-A-Z1-9_]+)'] = 'content/index/$1';  
    // again, you'll receive "Planning" as parameter to Content::index method
    
          

  • You still need a digital ID, so you don't need to change the controller / model:

    $route['(\d+)/[a-z-A-Z1-9_]+'] = 'content/index/$1';  
    // routes now look uglier: http://domain.com/6/Planning
    
          

+4


a source


http://codeigniter.com/user_guide/general/routing.html



you should be able to accomplish this with some examples on this page

0


a source







All Articles