HTTP 404 is the response given when you browsers interacted with the servers but no page was found at the location (URL).
This is important to know because for SEO and Google crawlers if they find an error such as nothing exists on the page or there is missing data a 404 will tell them that in theory nothing exists at this location, do not index.
I ran into the problem with vanity URL’s fetching and displaying data on the page based of a GET request in the URL. Meaning if there was no row in the database for that id the page would load up the predefined HTML without the dynamic PHP displayed values. It was unreadable and not a complete page.
This is an issue because theoretically infinite pages could exists that are broken and make no sense. I fixed this by checking for no rows found then display the 404 page not found error thus preventing bad crawl and SEO results.
This is simple done by setting the header:
header("HTTP/1.0 404 Not Found"); This will then state a 404 response and show the default 404 page (if any).
To state 404 and redirect to custom 404 page:
http_response_code(404);
include('custom_404.php');
die(); Very simple and actually underrated as being crucial in being a web crawler friendly website.
A drained and empty Kennington reservoir images from a drone in early July 2024. The…
Merrimu Reservoir from drone. Click images to view larger.
Using FTP and PHP to get an array of file details such as size and…
Creating and using Laravel form requests to create cleaner code, separation and reusability for your…
Improving the default Laravel login and register views in such a simple manner but making…
Laravel validation for checking if a field value exists in the database. The validation rule…