Welcome Guest, Not a member yet? Register   Sign In
404 Help
#1

[eluser]ci_user[/eluser]
How can I use a custom 404 page and still set the header status to 404?
The custom 404 in routes.php:
Code:
$route['404_override'] = 'my_controller/custom_404';

If I set the header status to 404, my custom error method shows the regular ugly server error 404 page.
Code:
function custom_404 () {
$this->output->set_status_header('404');
$this->load->view('my_error');
}

But if I do not set the header to 404 (pointless), my custom error works.
Code:
function custom_404 () {
//$this->output->set_status_header('404');
$this->load->view('my_error');
}

I see examples where folks have loaded a view or sent some other output after setting the header status to 404... how can I do that?
#2

[eluser]nagata[/eluser]
cant you just edit application/errors/error_404.php?
#3

[eluser]CroNiX[/eluser]
Try a regular header() and not use CI's for that one case.
header("HTTP/1.0 404 Not Found")

You can also put it at the very top of your view.
#4

[eluser]ci_user[/eluser]
Ok, it turns out I was actually seeing an IIS error page. Now I've redirected the server 404 page to my custom controller but now when I set the header:
Code:
function custom_404 () {
$this->output->set_status_header('404');
//or header("HTTP/1.0 404 Not Found");
$this->load->view('my_error');
}

All I get is a blank page. So the page header is working but I am still unable to load a view after setting it.

[quote author="CroNiX" date="1339257990"]Try a regular header() and not use CI's for that one case.
header("HTTP/1.0 404 Not Found")

You can also put it at the very top of your view.[/quote]
#5

[eluser]ci_user[/eluser]
[quote author="nagata" date="1339251740"]cant you just edit application/errors/error_404.php?[/quote]

I did originally try that. Strangely, editing that file has no effect at all.
#6

[eluser]ci_user[/eluser]
Update: Appears to be an IIS issue (surprise). IIS apparently won’t do a second http request after a 404 status is set. Instead, it will look for the file specified in IIS as the custom error page.

Read about it in this thread:
http://ellislab.com/forums/viewthread/204507/#954058




Theme © iAndrew 2016 - Forum software by © MyBB