Avoid 404 on controller not found?

#1
[eluser]JayTee[/eluser]
The CI documentation states:
Quote:Note that CodeIgniter automatically shows 404 messages if controllers are not found.
I'm wondering if there's a way for me to short-circuit that? For example, let's say someone does this:

http://www.example.com/correct_controlle...ect_method
http://www.example.com/incorrect_control...ect_method

If either of those happen, the user gets a 404 error "page not found"

Is there something I'm missing that will allow me to intercept the incorrect call and "roll up" to the correct url? For example:

http://www.example.com/incorrect_control...ect_method

redirects to:

http://www.example.com/ <-- we had to roll up to the next available "correct" controller

or another possibility:

http://www.example.com/correct_controlle...ect_method

redirects to:

http://www.example.com/correct_controller/ <-- loads index function



Any ideas/suggestions? I may have missed something in the docs, so a nudge will help, too Smile

#2
[eluser]JayTee[/eluser]
<bump>

Anyone? I still haven't found anything in the docs for this.

#3
[eluser]#1313[/eluser]
I personally think that this is bad practice to hide 404's from user and present them something that looks like almost what they are looking for. If user is doing something wrong, then he MUST know that he IS doing something wrong. IMHO, you should show 404 page and suggest some links to user that can lead them to their destination, but no automatic 'i-know-better-than-you-what-you-are-looking-for' redirects.

I know this is not an answer for your question, sorry =)

#4
[eluser]Phil Sturgeon[/eluser]
I personally believe the opposite is best. If you change something then its up to you to help the user find it without telling them they are stupid for using a 2 yr old bookmark.

In application/errors/ you can use basic PHP, so perhaps you could:

Quote:list($semgent1, $segment2) = explode $_SERVER['query_string']
if(file_exists(applications/controllers/$segment1)):
header(Location: $_SERVER['HTTP_HOST']/$segment1);
else:
header(Location: $_SERVER['HTTP_HOST']);
endif;

Thats pseudo with syntax, no copy and pasting :p

#5
[eluser]JayTee[/eluser]
[quote author="thepyromaniac" date="1191441162"]I personally believe the opposite is best. If you change something then its up to you to help the user find it without telling them they are stupid for using a 2 yr old bookmark.[/quote]

I agree! - I just wasn't sure how best to handle it.

[quote author="thepyromaniac" date="1191441162"]
In application/errors/ you can use basic PHP, so perhaps you could:

Code:
list($semgent1, $segment2) = explode $_SERVER['query_string']
if(file_exists(applications/controllers/$segment1)):
  header(Location: $_SERVER['HTTP_HOST']/$segment1);
else:
  header(Location: $_SERVER['HTTP_HOST']);
endif;
Thats pseudo with syntax, no copy and pasting :p[/quote]

Cool idea Smile I'm also considering using the error page with something like: "The page you have requested cannot be found. Please try:&lt;link to results of above pseudo-code&gt;"

Thanks!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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