Welcome Guest, Not a member yet? Register   Sign In
Using 404 Override won't trigger 404 header
#1

How can I add a 404 not found header to this code?
$routes->set404Override(static function () {
    return view('admin/others/error-page/error-404');
});

The problem with the code above is that when a page is not found (say a js script, css file etc...) the 404 header is not set and we cannot inspect which file failed loading.

TIA.
Reply
#2

See https://codeigniter4.github.io/CodeIgnit...4#override
Reply
#3

(11-24-2023, 08:46 PM)kenjis Wrote: See https://codeigniter4.github.io/CodeIgnit...4#override

Oh my... I should not have missed that crucial note! I appreciate your time. This is what I've come up with:

Code:
$routes->set404Override(static function () {
    response()->setStatusCode(404);
    return view('admin/others/error-page/error-404');
});
Reply
#4

Okay, good!

However, it seems strange that "404 override" does not return 404 response by default...
Reply
#5

(This post was last modified: 11-27-2023, 05:59 AM by sammyskills.)

You are correct @kenjis , it should return 404 response by default.
Reply
#6

(11-27-2023, 05:59 AM)sammyskills Wrote: You are correct @kenjis , it should return 404 response by default.

I fully agree. And I couldn't find a reason on the matter looking at the source code...
Reply
#7

It is because of historical reasons.
I don't know why, but CI3 does like that.

Personally, I would be happy to change it in the next minor version if it is well documented in:
- upgrade guide from CI3
- upgrade guide to 4.5.0
- changelog 4.5.0
- section "404 Override"
Reply




Theme © iAndrew 2016 - Forum software by © MyBB