Welcome Guest, Not a member yet? Register   Sign In
Basic routing question
#1

[eluser]piddleton[/eluser]
I've been through the routing section in the user guide which explains things clearly. However, I'm stuck on one thing...

I have a pretty basic site with a separate controller set up for each section:
about, news, bio, contact. If the user types something like: http://mysite.com/index.php/news then the news controller is successfully being called.

However, if they type any bogus page such as http://mysite.com/index.php/newsblahblah, I would like to always redirect them back to the news page (which is my home page).

Is the best way to do this to set up routing in routes.php for each controller, e.g. $route['news'] = "news". Then at the bottom of that list use $route['(:any)'] = "news";?

This seems to be working for me. But I'm wondering if this there's another, easier way to accomplish the same task instead of naming each controller in routes.php...


#2

[eluser]InsiteFX[/eluser]
Not sure if this will help but take a look at the _remap()

CodeIgniter Users Guide - Controllers - _remap()
#3

[eluser]piddleton[/eluser]
[quote author="InsiteFX" date="1338225012"]Not sure if this will help but take a look at the _remap()

CodeIgniter Users Guide - Controllers - _remap()
[/quote]

I'll give that a try - thanks!
#4

[eluser]Aken[/eluser]
I wouldn't recommend doing that. If a page doesn't exist, a 404 error should be returned. You can mess up your analytics, search engine results, possibly break your code (if something isn't set properly, like a relative URL for example), and potentially confuse users.

Now you can create a 404 page that has a link to your news page. That would be a much better idea.




Theme © iAndrew 2016 - Forum software by © MyBB