Yes, it's definitely possible to have multiple 404 pages for different purposes on a WordPress site, although it requires a bit of custom coding. You can achieve this by detecting the source of the 404 error and then redirecting to a specific 404 template based on the condition. Here’s a general approach to implement this:
Identify the Source of the 404 Error:
You need to determine the source of the 404 error. For instance, if it's a broken internal link or a mistyped URL.
This could be done by checking the HTTP referer, which tells you the previous page the user was on. Be aware that the referer might not always be set.
Create Custom 404 Templates:
Create different 404 templates in your theme for each type of error. For example, 404-internal.php for internal link errors and 404-external.php for mistyped URLs.
Modify the 404.php Template:
Edit the 404.php file in your theme.
Add a conditional check to determine the source of the 404 error.
Based on the condition, include the appropriate custom 404 template.
Here’s a basic example of what the code in your 404.php might look like:
<?php
$referer = $_SERVER['HTTP_REFERER'];
// Check if the referer is from your own domain
if (strpos($referer, home_url()) !== false) {
// This means it's an internal link that caused the 404
include('404-internal.php');
} else {
// This means it's likely a mistyped URL or an external link
include('404-external.php');
}
?>
Important Considerations:
The $_SERVER['HTTP_REFERER'] variable can be unreliable as it depends on the client's browser sending this information.
Make sure to handle cases where the referer is not set.
This solution assumes basic PHP and WordPress theme editing knowledge. If you're not comfortable with coding, you might want to consult with a developer.
Always back up your site before making changes to theme files.
By using this approach, you can provide a more tailored experience for users landing on your 404 pages, potentially improving user engagement and reducing bounce rates.
404.php
file you can actually check what url was called and redirect. You can also use a Redirect plugin to account for frequently erroring urls.