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

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


Code:
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index1');
$routes->setTranslateURIDashes(false);
//$routes->set404Override(function() {return view('404');});
//$routes->set404Override(function() {echo '404';});
$routes->set404Override();
$routes->setAutoRoute(true);



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


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

How to fix it in codeigniter 4?
Reply
#2

(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 

Reply
#3

Check status code of your 404 page here[url=https://httpstatus.io/][/url]
https://httpstatus.io/
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
Reply
#4

I use, I believe, a very simple solution:
PHP Code:
$routes->set404Override(function()
{
    $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">

<
head>
<
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>
</a>
</div>
<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" />
</form>
</div>
<nav class="site-nav">
<ul>
<li class="tools">
<a href="http://wdtools">Tools</a>
</li>
<li class="tools">
<a href="http://localhost/contacts" target="_blank">Contatos</a>
</li>
<li class="tools">
<a href="http://wdtest">Testes</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
</head>

<body> 
If plan A fails, relax... the alphabet is 26 letters
Reply
#5

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
https://httpstatus.io/
Reply
#6

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB