Welcome Guest, Not a member yet? Register   Sign In
How do I handle invalid controllers
#1

[eluser]The Mask[/eluser]
Hi,
What is the best way to handle invalid controllers?
For example, if somebody keys the URL as www.mysite.com/xyz where a controller does not exist called xyz. It would be cool to simply redirect this to the default controller without the user seeing any error message.
Thanks
#2

[eluser]Dam1an[/eluser]
There are 2 possible ways to di this that come to mind
1. Extending the Exception class, and instead of displaying the 404 page, redirect to your controller
2. Add a catch all route at the end whih points to your controller (You would need to define all your valid controllers before it though, so this can get a bit messy)
#3

[eluser]The Mask[/eluser]
Thanks for the quick reply.
I can't see any reference to an Exception class in the help though.
Any ideas?
#4

[eluser]Dam1an[/eluser]
The exception class is documents under errors
It can be found in
Code:
/system/libraries/Exceptions.php
#5

[eluser]Michael Wales[/eluser]
ew.. no no no - you should show a 404! The user is requesting a resource that doesn't exist, that is the definition of a 404.

By not throwing a 404 and instead redirecting to a controller you will get massive reductions in pagerank for duplicate content. Essentially, any of your competitors could create a page that links to 100 or so random, invalid controllers on your site, Google/Yahoo/MSN now see that 100 of your pages are exactly the same and they deduce that your site is nothing but spam.

You don't have to go with the default browser 404 design, you can design up the page however you want, add some helpful tips to the user (like links to what they may have been trying to access), etc. See this link for ideas: http://www.smashingmagazine.com/2009/01/...more-time/
#6

[eluser]sl3dg3hamm3r[/eluser]
[quote author="Michael Wales" date="1242061960"]By not throwing a 404 and instead redirecting to a controller you will get massive reductions in pagerank for duplicate content. Essentially, any of your competitors could create a page that links to 100 or so random, invalid controllers on your site, Google/Yahoo/MSN now see that 100 of your pages are exactly the same and they deduce that your site is nothing but spam.[/quote]

I never thought of that point. But I guess it is okay to set the header to a 404 (like in the default CI-errorpage), and show a nicely formatted page like 'oops, the called site doesn't exist etc.', by loading any view?
#7

[eluser]Michael Wales[/eluser]
Yeah - as long as you get that 404 in there.
#8

[eluser]sl3dg3hamm3r[/eluser]
errm... you mean besides the header I also need to have it as plain-text in the view?
#9

[eluser]The Mask[/eluser]
Thanks for the 404 info. Some interesting templates on the link too.
Best regards
#10

[eluser]Michael Wales[/eluser]
Quote:errm… you mean besides the header I also need to have it as plain-text in the view?
No - just the header() call is all that is required.




Theme © iAndrew 2016 - Forum software by © MyBB