• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Routes - why is trailing slash at the end ignored

#1
[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

#2
[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.


#3
[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?

#4
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.