A
A
arsenaljek2020-06-19 08:43:13
PHP
arsenaljek, 2020-06-19 08:43:13

How to return a 404 response?

Tell me how to give a 404 page correctly
. I have a template in which I determine by GET request whether there is an entry in the database and if so, then I show the page.

if (isset($_GET['shop'])) {
    $offer = isset($_GET['shop']) ? str_replace(" ", "", $_GET['shop']) : null;
    $sql = "SELECT * FROM shops WHERE link_shop = '".$offer."' ";
    $result = mysqli_query($linkMain,$sql);
}

That is, if the user enters the URL /view/?shop=mvideo.ru, the page will be found.
But it will also find it if the user enters something like /view/?shop=mvideo.ru1, etc.

I tried to wrap the page output in a condition that if the string is found, then we show the page, otherwise we return to the working page , redirect to 404 or immediately give the titleheader("HTTP/1.0 404 Not Found");
if (mysqli_num_rows($result) > 0) {

} else {
    
    // header("Location: /view/?shop=mvideo.ru");
// header("HTTP/1.0 404 Not Found");
    header("Location: /404/");
}

What is the right thing to do here so that the search engines respond adequately?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alekssamos, 2020-06-19
@alekssamos

header for search engines will be enough.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question