Rewriting URLs without invoking a different controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Rewriting URLs without invoking a different controller (/showthread.php?tid=19967) |
Rewriting URLs without invoking a different controller - El Forum - 06-24-2009 [eluser]mattpointblank[/eluser] Hi everyone, I'm new to CI. I run a news site. Our article URLs look like this: site.com/news/sport/ronaldo-signs-with-milan.html site.com/features/interview/bob-dylan.html site.com/news/comment/i-hate-capitalism.html In my current system, I use .htaccess to rewrite all URLs to point to article.php?section=news&category=sport&story=ronaldo-signs-with-milan - a little lengthy, but it works. I realise that if I was to apply these URLs to CodeIgniter, it would look for a 'news' or 'features' controller, rather than routing all of these requests through one 'article' controller. I looked briefly over the URI class, but I'm not certain if it's meant for this kind of thing. Can anyone give me a quick example (if it's possible) of how to achieve these kind of URLs while maintaining a normal CI structure? If it helps, I'm completely happy to include ID numbers in links (eg site.com/news/sport/123/ronaldo-signs-with-milan.html) if that makes it easier. Matt Rewriting URLs without invoking a different controller - El Forum - 06-24-2009 [eluser]Phil Sturgeon[/eluser] Take a look at URI Routing. Code: $route['(news|features)/(:any)'] = 'articles/$1/$2'; That should do the trick. Rewriting URLs without invoking a different controller - El Forum - 06-25-2009 [eluser]mattpointblank[/eluser] Thanks, worked great! Confusing as I dive into pagination but I think I have it, cheers! |