[英]How to use multiple 404 Error Pages in Wordpress
我有一个问题,但找不到解决方案。
我们有一个 Wordpress 页面,客户端需要多个错误页面。
对于我们创建的自定义主题,1 个错误页面位于通常的正常 404.php 中。 现在我想添加多个具有不同样式和 html 结构的错误页面。
例子:
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
我想不出一个好的解决方案如何正确完成并保存。
我考虑过像这里描述的那样更改 .htaccess: 404 重定向到多个错误页面.htaccess
但是如果永久链接被保存,.htaccess 将被重写,我的更改将消失在那里我也不知道如何将正确的错误文档放入其中(我的 rewriting.htaccess 知识不是最好的)我认为可能有一种编码方式php/js 什么的?
我还考虑过一些复杂的检查,如果这个 url 被调用,然后检查是否is_404()
但我想它太复杂了
在此先感谢您的帮助和提示:)
感谢 MrWhite 在 Wordpress 堆栈上提供的帮助,我不知道这些站点是相关的。 学到了新东西^^
我设法在这里完成它是我的答案: https://wordpress.stackexchange.com/questions/410101/how-to-use-multiple-404-error-pages-in-wordpress/410133#410133
我也可以将它复制到这里,如果搜索到的字符串存在,我将在 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.