SULTAN
SULTAN

Reputation: 1159

how to redirect the user to Page 404 from URL

I have a php script that redirect the user to a specific page based on a record id (e.g. example.com/page.php?id=4)

My question is: How can I redirect the user to the 404 Error page if he type in the browser a record id that doesn't exists? (e.g. example.com/page.php?id=59542)

Although, putting an id that doesn't exists in the DB shows no data, but the user still can see the page template.. but with empty data...

Thanks

Upvotes: 2

Views: 738

Answers (3)

user3152750
user3152750

Reputation: 128

Using if statements check if there is such ID in the database, if it does not exist, do: header("Location: 404.php"); You can change 404.php to your 404 file location.

Upvotes: 4

You can create a page, (a complete page, with CSS, ...) and redirect to that page every 404.

Example: Look what google does https://www.google.com/adlkfjaoie43 they created a page to redirect to.

Upvotes: 0

Hanlet Escaño
Hanlet Escaño

Reputation: 17380

You should send a 404 header, and maybe display a custom not found page:

<?php 
    header("HTTP/1.0 404 Not Found"); 
    include("404.php"); 
?> 

Upvotes: 2

Related Questions