Routes - why is trailing slash at the end ignored |
[eluser]Unknown[/eluser]
I want to make rules for my cms pages and for articles pages. Cms pages should ends with http://www.domain.com/index.php/cms-page-title/ http://www.domain.com/index.php/article-title I tried $route['([a-zAZ0-9_-]+)/$'] = "cms/show/$1"; $route['([a-zAZ0-9_-]+)$'] = "articles/show/$1"; but this is not working as expected. Everytime I get articles. I don't understand why $route['([a-zAZ0-9_-]+)/$'] is ignored if I to to http://www.domain.com/index.php/cms-page-title/. I know that alternative is to change .htaccess, but I want to understand why this is not working. Does anybody have any idea? tnx
[eluser]jotorres1[/eluser]
You should consider having atleast the class shown before the article name. For example: Code: http://domain.com/index.php/cms/cms-page-title That way, you can specify in the routes file with precision. Code: $route['cms/(:any)'] = 'cms/show/$1'; I recommend it this way, since you will not always try to access the cms controller. Don't forget about all other controllers, such as, profile, users, admin, etc.
[eluser]Unknown[/eluser]
For all other controllers is domain.com/controller/method/parm or domain.com/controller/IndexParm, so there won't be any conflict. I want to keep for cms page domain.com/cms-page-title/ for SEO and linking purposes. So back to the question, why $route['([a-zAZ0-9_-]+)/$'] = "cms/show/$1"; is ignored?
[eluser]jotorres1[/eluser]
Thing is, you are using a regular expression on your first segment, highly not recommended. You should read up on routing within the user guide User Guide: Routing Especially the last sentence. Second, you can also try _remap(). I wrote about it here: Remapping function calls in Codeigniter Hope that helps. |
Welcome Guest, Not a member yet? Register Sign In |