404 Errors |
[eluser]omed habib[/eluser]
Is there a prebuilt standard method for custom 404 pages? How do I have CI redirect 404 errors to a custom controller/function rather than the standard error_404.php? Thanks
[eluser]Vince Stross[/eluser]
Read this page in the User Guide for some good information on CI's built in 404 handling, etc. http://ellislab.com/codeigniter/user-gui...rrors.html
[eluser][email protected][/eluser]
if you are doing a redirect, how do you pass the actual message onto the custom error page? Also, how does CI do it today? ie. if you type in http://codeigniter.com/jibberishlkjslkjf then you are forwarded to a custom 404 page (the headers and footer looks the same); thus, it displays '404' but still keeps the url the same "http://codeigniter.com/jibberishlkjslkjf"? How could we write something like that?
[eluser]TheFuzzy0ne[/eluser]
Can you not extend the CI_Exceptions class in /system/libraries/Exception.php and then override the show_404 method? Alternatively, you can rewrite the error_404.php file to do what you want it to. I would suggest that you don't pass it to another controller however, as that has already been done. You would need to write a library or some helper functions to do what you want.
[eluser][email protected][/eluser]
I figured this out and implemented it. Let me know if you need the solution. Basically, there are two options where an error can be called. 1) inside the controller (ie. during a calculation) or 2) before the controller (ie. pre-controller hook) So the exceptions class is overriden and a check is performed whether a &get;_instance() exists.
[eluser]meade[/eluser]
I had the same issue - I just changed my website and wanted the people to go to MY 404 page instead of the standard error page, so I modified the system/applications/errors/error_404.php page to: <? header( 'Location: http://www.yoursite.org/yourcontroller/your404function') ; ?> which routed the 404's to my specific controller/function which then allowed me to show my 404 page (remember with header nothing before nothing after the line.
[eluser][email protected][/eluser]
Keep in mind that you are doing a redirect, and the page name will change to /yourcontroller/your404function...which I found to be a pain.....I wanted to display the 404 error but keep the url the same /originalcontroller/normal_function....not 404....
[eluser]wr5aw[/eluser]
I have a simple 'pages' controller that uses a combination of htaccess and _remap() to create a custom 404 page. In my controller, I do this: Code: function _remap($page='index') Code: <h2>Oops... I couldn't find that page</h2> Code: <html> |
Welcome Guest, Not a member yet? Register Sign In |