A
A
Alexey2016-01-31 05:47:55
Search Engine Optimization
Alexey, 2016-01-31 05:47:55

How to correctly issue 404?

Hello! I wrote some kind of cms for my own needs, but here's the problem...
I have rewrites written in .htaccess like this:

RewriteRule ^article/$   /index.php?mode=articles
RewriteRule ^catalog/$   /index.php?mode=section
RewriteRule ^catalog/([0-9a-z_-]{1,32})/$  /index.php?mode=section&tags=$1

Well, everything works as it should, but if you write something extraordinary like site.ru/sdfgsdfgs/sdfhgsdf/sdfsfdssf/
That in the address, without any problems, the server returns the response code 200 and shows the main page.
I understand that the structure was not initially thought out correctly, but in which direction should I think? What logic should be in such a case?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Tretyakov, 2016-01-31
@dzheka3d

Since you have made some kind of cms, I still advise you to improve it and
move away from forming links in htaccess. Make CNC in pure PHP and
your mobility will have no limits, and error handling will be
much more primitive and will be reduced to the usual logical if else constructs.
Googled a bit, here's a great article on how to create a CNC with
PHP. First it talks about how to do it with htaccess, and then
comes just what you need, starting with the CNC header in PHP and two examples
with different implementations.
Don't be lazy and figure it out :).
And the server response is 404 Not Found, in PHP it will look like this:
When a person opens a page on your site, you should have a check to see if
that page exists in your database or files. And if not,
then give the server a 404 response, and for the user display a message about the
non-existence of the page.

S
Stalker_RED, 2016-01-31
@Stalker_RED

After all, in some place you check what "mode" is equal to, and a call is made to the appropriate modules.
Here it also turns out that sdfgsdfgs/sdfhgsdf/sdfsfdssf is missing on the site. So you need to show 404.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question