V
V
Vladimir Homenok2015-01-02 22:24:55
PHP
Vladimir Homenok, 2015-01-02 22:24:55

How to make a 404 redirect when routing?

Not so long ago, Toaster suggested me a very cool topic with routing and php, thank you very much:3
And now, when I almost rewrote my "engine", I had a question about 404 redirects.
I tried to do this:
First, if the url does not fit any rules, the router thinks that this is an article (because the article can be anywhere).

else {
        $this -> set('ContentManager', new ArticleManager($address, $this['database']));
        $route_to = 'article';
}

The article itself checks its URL against the database, if it doesn’t find anything there, it redirects to the page with 404.
if (count($this -> mysql_content) == 0) {
        header( "Location: /error404.php", true, 404 );
        exit();
}

When my page started redirecting to 404s, I was initially delighted. "Just write in .htaccess, and you're done!".
79009c0f315042518188ee0c3d452612.PNG
ErrorDocument 404 http://klimatdomu.ru/error404.php

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.klimatdomu.ru$ [NC]
RewriteRule ^(.*)$ http://klimatdomu.ru/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

But for some reason this thing does not work, the site still hangs on 404
88759f9dc2844f16b5a807ad8df5a43c.PNG
I would be grateful if someone points out where I went wrong, and how can I implement this? Page with 404 - error404.php
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Artemyev, 2015-01-03
@MrHamster

header( "Location: /error404.php", true, 404);
The browser is getting a 404 response and is most likely not executing "Location: /error404.php" because of this.
Try this
header("Location: /error404.php", true);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question