CodeIgniter Forums
How do I route "mysite.com/clean-article-title" to the correct controller ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How do I route "mysite.com/clean-article-title" to the correct controller ? (/showthread.php?tid=8778)



How do I route "mysite.com/clean-article-title" to the correct controller ? - El Forum - 05-30-2008

[eluser]little brittle[/eluser]
I'm having trouble figuring out how to set up CI so that "mysite.com/clean-article-title" routes to "mysite.com/blog/article/clean-article-title". I was directed to an article here:
http://remysharp.com/2008/03/25/codeigniter/

But I can't figure out how to get this working. Could anyone explain the easiest way to get this working?


How do I route "mysite.com/clean-article-title" to the correct controller ? - El Forum - 05-30-2008

[eluser]Bramme[/eluser]
[quote author="little brittle" date="1212193742"]I'm having trouble figuring out how to set up CI so that "mysite.com/clean-article-title" routes to "mysite.com/blog/article/clean-article-title". I was directed to an article here:
http://remysharp.com/2008/03/25/codeigniter/

But I can't figure out how to get this working. Could anyone explain the easiest way to get this working?[/quote]
Try this

$routes['([a-z0-9-]+)'] = "blog/article/$1";

NOTE: you can't use CAPITAL letters in your clean article title. If you want to, use [a-zA-Z0-9-]as regex.


How do I route "mysite.com/clean-article-title" to the correct controller ? - El Forum - 05-30-2008

[eluser]little brittle[/eluser]
Well, that would work. But wouldn't you have to specify all of your controllers in the 'routes' file before that line? Right now it doesn't check for a controller match and thinks everything is a blog article.


How do I route "mysite.com/clean-article-title" to the correct controller ? - El Forum - 05-31-2008

[eluser]Bramme[/eluser]
[quote author="little brittle" date="1212204522"]Well, that would work. But wouldn't you have to specify all of your controllers in the 'routes' file before that line? Right now it doesn't check for a controller match and thinks everything is a blog article.[/quote]

True, everything will be a blog entry... I don't really know how els you could do it... You could try smth like mysite.com/blog-clean-title/ and then use regex to cut off the blog, incicating it's a blog entry...

Sudden idea: you can use multiple routes. For instance, you could use:

$route['([a-z0-9-]+)'] = "blog/blahblah/$1";
$route['controller/(:any)'] = "controller/$1";

etc...