Answer the question
In order to leave comments, you need to log in
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
site.ru/sdfgsdfgs/sdfhgsdf/sdfsfdssf/
Answer the question
In order to leave comments, you need to log in
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.
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 questionAsk a Question
731 491 924 answers to any question