Welcome Guest, Not a member yet? Register   Sign In
Rewriting URLs without invoking a different controller
#1

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

[eluser]Phil Sturgeon[/eluser]
Take a look at URI Routing.

Code:
$route['(news|features)/(:any)'] = 'articles/$1/$2';

That should do the trick.
#3

[eluser]mattpointblank[/eluser]
Thanks, worked great! Confusing as I dive into pagination but I think I have it, cheers!




Theme © iAndrew 2016 - Forum software by © MyBB