Welcome Guest, Not a member yet? Register   Sign In

On my page https://www.trzyksiezyce.pl I have default 404 page

//$routes->set404Override(function() {return view('404');});
//$routes->set404Override(function() {echo '404';});

Which gives 404 status code on
Bulk URL HTTP Status Code, Header & Redirect Checker | httpstatus.io

When I toggle to
$routes->set404Override(function() {echo '404';});
$routes->set404Override(function() {return view('404');});
It gives 200 status code

How to fix it in codeigniter 4?

(This post was last modified: 12-20-2021, 11:41 AM by captain-sensible. Edit Reason: extar )

a simple lateral thinking approach is to test via logic whether the page exists , i.e the view exits in views - thats the approach i've taken ,if the page can't be found i simply redirect to a custom page can't be found . have a look By typing something after the domain i have listed via CMS link.

I 'll make it easy go to this link : https://andrinadesignstudio.com/noPage

My custom 404 is called nopage and thats what gets called if anything can't be found. For ultra nerds you can click on the music play while you read
CMS CI4     I use Arch Linux by the way 


Check status code of your 404 page here[url=https://httpstatus.io/][/url]
It's 200 but should be 404. It's problem for indexing page in google.
My https://www.trzyksiezyce.pl/sth page display default page 404 because codeigniter 4 custom 404 page gives wrong status code.
And I am tring to solve this problem in forum

I use, I believe, a very simple solution:
PHP Code:
    $header = array(
    'css' => 'nodata',
    'title' => 'wdeda | Page Not Found'
echo view('templates/headerr'$header);
    echo view('content/error_404');
    echo view('templates/footerfb');

Where 'css' and 'title' correspond to variables used in the page header.
PHP Code:
<!DOCTYPE html>
html lang="pt-br">

meta charset="UTF-8">
meta name="viewport" content="width=device-width, initial-scale=1.0">
meta name="description" content="Catálogo privado de filmes e músicas">
link href="/assets/css/header.css" rel="stylesheet">
link href="/assets/css/<?= $css ?>.css" rel="stylesheet">
title><?= $title ?></title>
<div class="header-main-nav">
<div class="max-header">
<div class="main-nav">
<div class="logo-container">
<a class="logo" href="/">
<h1 class="logo-img">wdeda</h1>
<div class="search-container">
<form action="/search" class="site-search" method="post" name="site-search">
<input class="site-search-button" name="wdeda" type="submit" />
<input class="site-search-input" name="search" placeholder="Pesquisar" tabindex="1" type="search" />
<nav class="site-nav">
<li class="tools">
<a href="http://wdtools">Tools</a>
<li class="tools">
<a href="http://localhost/contacts" target="_blank">Contatos</a>
<li class="tools">
<a href="http://wdtest">Testes</a>

If plan A fails, relax... the alphabet is 26 letters

But it should return HTTP 404 status code, check it. NOT HTTP 200 OK but HTTP 404. 
My custom 404 page, which was made similar as yours and it returns HTTP 200 OK, so I am using now default 404 page (which returns HTTP 404)
You can check it here

(This post was last modified: 12-21-2021, 09:39 AM by DawiD.)

I solve the problem by replace file app/Views/errors/html/error_404.php
by my file. Is it proper way to display custom 404 page in codeigniter 4?
I think the way
PHP Code:
$routes->set404Override(function() {return view('404');}); 
is not good solution because it return HTTP 200 OK

Theme © iAndrew 2016 - Forum software by © MyBB