i have a question and couldn't find a solution for it.
We have a Wordpress page where the client wants multiple error pages.
1 error page is in the usual normal 404.php for the custom theme which we created. Now i wanted to add multiple error pages with different styling and html structure.
example:
localhost/blog/{post-name} -> if this post name is not found load me the post-404-error.php
localhost/service/{service-name} -> if service was not found load the service-404-error.php
i couldn't think of a good solution how to get it done the right and save way.
i thought about changing the .htaccess like here described: 404 redirection to multiple error page.htaccess
but if permalinks are saved the .htaccess is rewritten and my changed will be gone there also i didn't know how to put the correct error documents inside ( my rewriting.htaccess knowledge is not the best) i thought there could be a coded way with php/js something?
i also thought about some complicating check if this url is called and then check if is_404()
but i guess its to complicated
thanks in advance for any help and tips:)
Thanks MrWhite for your help on the Wordpress stack i didn't know that those sites were related. learned something new ^^
i managed to get it done here is my answer: https://wordpress.stackexchange.com/questions/410101/how-to-use-multiple-404-error-pages-in-wordpress/410133#410133
i can also copy it inside here, im checking in the 404.php in wordpress onlyt the url if the searched string is present and then show the template
$postUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
get_header();
if (strpos($postUrl,'services') !== false) {
get_template_part("error-pages/services-error-page");
} elseif(strpos($postUrl,'blog') !== false) {
get_template_part("error-pages/blog-post-error");
}else{
get_template_part("error-pages/general-404-error");
}
get_footer();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.