简体   繁体   English

Wordpress中如何使用多个404错误页面

[英]How to use multiple 404 Error Pages in Wordpress

i have a question and couldn't find a solution for it.我有一个问题,但找不到解决方案。

We have a Wordpress page where the client wants multiple error pages.我们有一个 Wordpress 页面,客户端需要多个错误页面。

1 error page is in the usual normal 404.php for the custom theme which we created.对于我们创建的自定义主题,1 个错误页面位于通常的正常 404.php 中。 Now i wanted to add multiple error pages with different styling and html structure.现在我想添加多个具有不同样式和 html 结构的错误页面。

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我考虑过像这里描述的那样更改 .htaccess: 404 重定向到多个错误页面.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?但是如果永久链接被保存,.htaccess 将被重写,我的更改将消失在那里我也不知道如何将正确的错误文档放入其中(我的 rewriting.htaccess 知识不是最好的)我认为可能有一种编码方式php/js 什么的?

i also thought about some complicating check if this url is called and then check if is_404() but i guess its to complicated我还考虑过一些复杂的检查,如果这个 url 被调用,然后检查是否is_404()但我想它太复杂了

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.感谢 MrWhite 在 Wordpress 堆栈上提供的帮助,我不知道这些站点是相关的。 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我设法在这里完成它是我的答案: 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我也可以将它复制到这里,如果搜索到的字符串存在,我将在 wordpress 中检查 404.php,仅检查 url,然后显示模板

$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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM