{"id":3779,"date":"2025-06-12T04:26:36","date_gmt":"2025-06-11T20:26:36","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/wpcms\/wpdt\/3779.html"},"modified":"2025-06-12T04:26:36","modified_gmt":"2025-06-11T20:26:36","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-wordpress-%e4%b8%ad%e8%bd%bb%e6%9d%be%e8%b7%9f%e8%b8%aa-404-%e9%a1%b5%e9%9d%a2%e5%b9%b6%e9%87%8d%e5%ae%9a%e5%90%91%e5%ae%83%e4%bb%ac","status":"publish","type":"post","link":"https:\/\/www.zhaozhao123.cn\/wpcms\/post\/3779.html","title":{"rendered":"\u5982\u4f55\u5728 WordPress \u4e2d\u8f7b\u677e\u8ddf\u8e2a 404 \u9875\u9762\u5e76\u91cd\u5b9a\u5411\u5b83\u4eec"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">Bug&#32534;&#35793;&#29422;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312;WordPress&#20013;&#35774;&#32622;404&#38169;&#35823;&#39029;&#38754;&#21644;&#23454;&#29616;&#33258;&#21160;&#37325;&#23450;&#21521;&#21487;&#20197;&#24110;&#21161;&#29992;&#25143;&#26356;&#22909;&#22320;&#29702;&#35299;&#32593;&#31449;&#30340;&#32467;&#26500;&#21644;&#21151;&#33021;&#12290;&#20197;&#19979;&#26159;&#22914;&#20309;&#22312;WordPress&#20013;&#35774;&#32622;404&#38169;&#35823;&#39029;&#38754;&#20197;&#21450;&#23454;&#29616;&#33258;&#21160;&#37325;&#23450;&#21521;&#30340;&#35814;&#32454;&#27493;&#39588;&#12290;<\/p>\n<h3>&#27493;&#39588;1&#65306;&#21019;&#24314;&#25110;&#32534;&#36753;404&#38169;&#35823;&#39029;&#38754;<\/h3>\n<p>&#39318;&#20808;&#65292;&#22312;&#24744;&#30340;WordPress&#21518;&#21488;&#65292;&#23548;&#33322;&#21040;<code>Appearance &gt; Themes<\/code>&#65288;&#25110;<code>Settings &gt; Reading<\/code>&#65289;&#65292;&#28982;&#21518;&#36873;&#25321;&#24744;&#24076;&#26395;&#26174;&#31034;404&#38169;&#35823;&#39029;&#38754;&#30340;&#20027;&#39064;&#12290;&#28857;&#20987;&ldquo;Edit&rdquo;&#25353;&#38062;&#26469;&#32534;&#36753;&#36825;&#20010;&#20027;&#39064;&#12290;<\/p>\n<ul>\n<li><strong>&#28155;&#21152;404&#38169;&#35823;&#39029;&#38754;<\/strong>&#65306;&#22312;&#27169;&#26495;&#25991;&#20214;&#20013;&#25214;&#21040;&#19982;404&#38169;&#35823;&#30456;&#20851;&#30340;&#37096;&#20998;&#65292;&#36890;&#24120;&#20301;&#20110;<code>functions.php<\/code>&#25991;&#20214;&#20869;&#12290;&#24744;&#21487;&#20197;&#26681;&#25454;&#38656;&#35201;&#28155;&#21152;&#19968;&#20010;&#26032;&#39029;&#38754;&#25110;&#20462;&#25913;&#29616;&#26377;&#39029;&#38754;&#20197;&#26174;&#31034;404&#38169;&#35823;&#20449;&#24687;&#12290;<\/li>\n<\/ul>\n<h3>&#31034;&#20363;&#20195;&#30721;&#65306;<\/h3>\n<pre><code class=\"language-php\">\/\/ &#22312;functions.php&#20013;&#28155;&#21152;&#20197;&#19979;&#20195;&#30721;&#29255;&#27573;&#65306;\nfunction custom_404_page() {\n    if ( is_404() ) {\n        \/\/ &#26816;&#26597;&#26159;&#21542;&#24050;&#23384;&#22312;&#21517;&#20026;'custom_error_page'&#30340;&#33258;&#23450;&#20041;&#39029;&#38754;\n        $page_id = get_page_by_title( 'Custom Error Page', OBJECT, 'post' );\n\n        if ( !empty($page_id) &amp;&amp; $page_id-&gt;ID != 0 ) {\n            echo '&lt;h2&gt;' . esc_html__( 'Oops! This page could not be found.', 'textdomain' ) . '&lt;\/h2&gt;';\n            echo '&lt;p&gt;' . esc_html__( 'The page you are looking for might have been removed or it may no longer exist. Please try using the search box below to find what you are looking for.', 'textdomain' ) . '&lt;\/p&gt;';\n\n            \/\/ &#20351;&#29992;&#25628;&#32034;&#26694;\n            echo '&lt;form method=\"get\" action=\"' . home_url('\/') . '\" class=\"search-form\"&gt;';\n            echo '&lt;label for=\"s\"&gt;' . esc_attr__( 'Search:', 'textdomain' ) . '&lt;\/label&gt;';\n            echo '&lt;input type=\"search\" name=\"s\" id=\"s\" placeholder=\"' . esc_attr__( 'Type here...' , 'textdomain') . '\" value=\"' . isset($_GET['s']) ? $_GET['s'] : '' . '\" \/&gt;';\n            echo '&lt;button type=\"submit\" class=\"search-submit\"&gt;' . esc_html__( 'Search', 'textdomain' ) . '&lt;\/button&gt;';\n            echo '&lt;\/form&gt;';\n        } else {\n            wp_redirect(home_url('\/error-page\/'));\n            exit;\n        }\n    }\n}\nadd_action('template_redirect','custom_404_page');<\/code><\/pre>\n<h3>&#27493;&#39588;2&#65306;&#37197;&#32622;&#33258;&#21160;&#37325;&#23450;&#21521;<\/h3>\n<p>&#25509;&#19979;&#26469;&#65292;&#25105;&#20204;&#38656;&#35201;&#37197;&#32622;WordPress&#20197;&#22312;404&#38169;&#35823;&#26102;&#33258;&#21160;&#37325;&#23450;&#21521;&#21040;&#25105;&#20204;&#30340;&#33258;&#23450;&#20041;&#39029;&#38754;&#12290;&#36825;&#21487;&#20197;&#36890;&#36807;&#20462;&#25913;WordPress&#30340;&#20027;&#37197;&#32622;&#25991;&#20214;<code>wp-config.php<\/code>&#26469;&#23436;&#25104;&#12290;<\/p>\n<ul>\n<li>&#25214;&#21040;&#20197;&#19979;&#34892;&#65306;<\/li>\n<\/ul>\n<pre><code class=\"language-php\">define('WP_HOME', 'http:\/\/example.com\/');\ndefine('WP_SITEURL', 'http:\/\/example.com\/');<\/code><\/pre>\n<ul>\n<li>&#23558;&#36825;&#20004;&#20010;&#23450;&#20041;&#26367;&#25442;&#20026;&#25351;&#21521;&#24744;&#30340;&#32593;&#31449;&#26681;&#30446;&#24405;&#30340;&#32477;&#23545;&#36335;&#24452;&#65306;<\/li>\n<\/ul>\n<pre><code class=\"language-php\">define('WP_HOME', '\/\/your-site-url.com\/');\ndefine('WP_SITEURL', '\/\/your-site-url.com\/');<\/code><\/pre>\n<p>&#20363;&#22914;&#65292;&#22914;&#26524;&#24744;&#30340;&#32593;&#31449;&#22320;&#22336;&#26159; <code>www.example.com<\/code>&#65292;&#21017;&#24212;&#25913;&#20026;&#65306;<\/p>\n<pre><code class=\"language-php\">define('WP_HOME', 'https:\/\/www.example.com\/');\ndefine('WP_SITEURL', 'https:\/\/www.example.com\/');<\/code><\/pre>\n<h3>&#27493;&#39588;3&#65306;&#27979;&#35797;&#24744;&#30340;&#35774;&#32622;<\/h3>\n<p>&#20445;&#23384;&#26356;&#25913;&#21518;&#65292;&#20877;&#27425;&#35775;&#38382;404&#38169;&#35823;&#39029;&#38754;&#65292;&#24744;&#24212;&#35813;&#20250;&#30475;&#21040;&#26032;&#30340;404&#39029;&#38754;&#32780;&#19981;&#26159;&#24120;&#35268;&#30340;404&#39029;&#38754;&#20102;&#12290;&#21516;&#26102;&#65292;&#24403;&#23581;&#35797;&#35775;&#38382;&#19981;&#23384;&#22312;&#30340;&#39029;&#38754;&#26102;&#65292;&#23427;&#24212;&#35813;&#20250;&#34987;&#33258;&#21160;&#37325;&#23450;&#21521;&#21040;&#24744;&#25351;&#23450;&#30340;&#33258;&#23450;&#20041;&#39029;&#38754;&#12290;<\/p>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#24744;&#21487;&#20197;&#22312;WordPress&#20013;&#36731;&#26494;&#22320;&#35774;&#32622;&#21644;&#31649;&#29702;404&#38169;&#35823;&#39029;&#38754;&#21450;&#20854;&#33258;&#21160;&#37325;&#23450;&#21521;&#21151;&#33021;&#65292;&#20174;&#32780;&#25552;&#20379;&#26356;&#22909;&#30340;&#29992;&#25143;&#20307;&#39564;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;&#21069;&#30340;Bug&#35821;&#27861;&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<p class=\"my-0\">&#40657;&#26495;&#21069;&#30340;Bug&#35821;&#27861;&#35762;&#24072;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312;WordPress&#20013;&#23454;&#29616;404&#39029;&#38754;&#36861;&#36394;&#21644;&#37325;&#23450;&#21521;&#21151;&#33021;&#26159;&#19968;&#39033;&#26082;&#31616;&#21333;&#21448;&#23454;&#29992;&#30340;&#20219;&#21153;&#12290;&#19979;&#38754;&#25105;&#23558;&#25552;&#20379;&#19968;&#20010;&#35814;&#32454;&#30340;&#27493;&#39588;&#26469;&#25351;&#23548;&#24744;&#23436;&#25104;&#36825;&#20010;&#36807;&#31243;&#12290;<\/p>\n<h3>&#27493;&#39588;1: &#23433;&#35013;&#21644;&#35774;&#32622;404&#38169;&#35823;&#22788;&#29702;&#25554;&#20214;<\/h3>\n<p>&#39318;&#20808;&#65292;&#38656;&#35201;&#23433;&#35013;&#24182;&#21551;&#29992;&#19968;&#20010;404&#38169;&#35823;&#22788;&#29702;&#25554;&#20214;&#65292;&#20197;&#30830;&#20445;&#24744;&#30340;&#32593;&#31449;&#33021;&#22815;&#27491;&#30830;&#22320;&#22788;&#29702;404&#38169;&#35823;&#12290;&#25512;&#33616;&#20351;&#29992;&ldquo;WP Error 404&rdquo;&#25554;&#20214;&#65292;&#22240;&#20026;&#23427;&#21487;&#20197;&#33258;&#21160;&#26816;&#27979;&#21644;&#26174;&#31034;404&#38169;&#35823;&#39029;&#38754;&#65292;&#21516;&#26102;&#25552;&#20379;&#21508;&#31181;&#36873;&#39033;&#26469;&#23450;&#21046;404&#38169;&#35823;&#25552;&#31034;&#12290;<\/p>\n<h4>&#31034;&#20363;&#20195;&#30721;&#65306;<\/h4>\n<pre><code class=\"language-html\">&lt;!-- wp-content\/themes\/your-theme\/inc\/error-404.php --&gt;\n&lt;div class=\"error-404\"&gt;\n    &lt;h2&gt;Error 404 - Page Not Found&lt;\/h2&gt;\n    &lt;p&gt;Sorry, but the page you're looking for doesn't exist.&lt;\/p&gt;\n&lt;\/div&gt;<\/code><\/pre>\n<h3>&#27493;&#39588;2: &#20351;&#29992;HTTP Status Code 404<\/h3>\n<p>&#22312;&#24744;&#30340;&#20027;&#39064;&#25991;&#20214;&#22841;&#19979;&#21019;&#24314;&#25110;&#20462;&#25913;&#19968;&#20010;&#21517;&#20026;<code>functions.php<\/code>&#30340;&#25991;&#20214;&#65288;&#22914;&#26524;&#36824;&#27809;&#26377;&#30340;&#35805;&#65289;&#65292;&#28982;&#21518;&#28155;&#21152;&#20197;&#19979;&#20195;&#30721;&#65306;<\/p>\n<pre><code class=\"language-php\">function redirect_404() {\n    if (isset($_SERVER['HTTP_REFERER'])) {\n        header(\"Location: \" . $_SERVER['HTTP_REFERER']);\n        exit;\n    }\n}\nadd_action('template_redirect', 'redirect_404');<\/code><\/pre>\n<p>&#36825;&#27573;&#20195;&#30721;&#20250;&#22312;&#29992;&#25143;&#35775;&#38382;&#19981;&#23384;&#22312;&#30340;&#39029;&#38754;&#26102;&#31435;&#21363;&#36339;&#36716;&#21040;&#40664;&#35748;&#30340;404&#39029;&#38754;&#12290;<\/p>\n<h3>&#27493;&#39588;3: &#36319;&#36394;&#24182;&#31649;&#29702;404&#39029;&#38754;<\/h3>\n<p>&#25509;&#19979;&#26469;&#65292;&#22312;&#24744;&#30340;&#20027;&#39064;&#25991;&#20214;&#22841;&#19979;&#30340;<code>functions.php<\/code>&#25991;&#20214;&#20013;&#28155;&#21152;&#20197;&#19979;&#20195;&#30721;&#65306;<\/p>\n<pre><code class=\"language-php\">\/\/ &#33719;&#21462;&#24403;&#21069;URL\n$current_url = home_url();\n\n\/\/ &#21019;&#24314;404&#39029;&#38754;&#38142;&#25509;\n$404_page_link = get_home_url() . '\/404';\n\n\/\/ &#22914;&#26524;&#24403;&#21069;URL&#19982;404&#39029;&#38754;&#19981;&#21305;&#37197;&#65292;&#21017;&#29983;&#25104;404&#39029;&#38754;\nif ($current_url != $404_page_link) {\n    add_action('wp_head', function () use ($current_url, $404_page_link) {\n        echo '&lt;link rel=\"canonical\" href=\"' . $404_page_link . '\" \/&gt;';\n    });\n}\n\n\/\/ &#26816;&#26597;&#26159;&#21542;&#38656;&#35201;&#26174;&#31034;404&#39029;&#38754;\nif (!is_front_page()) {\n    $content = '';\n    \/\/ &#28155;&#21152;&#33258;&#23450;&#20041;&#20869;&#23481;\n    if ($_GET &amp;&amp; !empty($_GET['page_id'])) {\n        $content .= \"&lt;div class='404-page'&gt;\";\n        $post = get_post($_GET['page_id']);\n        $content .= '&lt;a href=\"' . esc_url(get_permalink($post-&gt;ID)) . '\"&gt;' . $post-&gt;post_title . '&lt;\/a&gt;';\n        $content .= \"&lt;\/div&gt;\";\n    } else {\n        $content .= \"&lt;div class='404-page'&gt;Page not found&lt;\/div&gt;\";\n    }\n\n    \/\/ &#23558;404&#20869;&#23481;&#25554;&#20837;&#21040;&#30456;&#24212;&#30340;&#20301;&#32622;\n    if (isset($_GET['pagenotfound']) || isset($_GET['page_not_found'])) {\n        $content = apply_filters('the_content', $content);\n    }\n\n    \/\/ &#36755;&#20986;404&#20869;&#23481;\n    echo do_shortcode('[shortcode_here]' . $content);\n}<\/code><\/pre>\n<p>&#36825;&#27573;&#20195;&#30721;&#30340;&#20027;&#35201;&#30446;&#30340;&#26159;&#26816;&#26597;&#24403;&#21069;URL&#26159;&#21542;&#20026;404&#39029;&#38754;&#65292;&#22914;&#26524;&#26159;&#65292;&#21017;&#36755;&#20986;&#33258;&#23450;&#20041;&#30340;404&#39029;&#38754;&#20869;&#23481;&#12290;&#27492;&#22806;&#65292;&#23427;&#36824;&#20250;&#26681;&#25454;&#19981;&#21516;&#30340;&#24773;&#20917;&#28155;&#21152;&#19968;&#20010;&#38142;&#25509;&#21040;404&#39029;&#38754;&#65292;&#36825;&#26377;&#21161;&#20110;&#25628;&#32034;&#24341;&#25806;&#26356;&#22909;&#22320;&#29702;&#35299;404&#38382;&#39064;&#12290;<\/p>\n<h3>&#27493;&#39588;4: &#37197;&#32622;404&#39029;&#38754;&#26679;&#24335;<\/h3>\n<p>&#26368;&#21518;&#19968;&#27493;&#26159;&#37197;&#32622;404&#39029;&#38754;&#30340;&#26679;&#24335;&#12290;&#24744;&#21487;&#20197;&#21019;&#24314;&#19968;&#20010;CSS&#31867;&#25110;&#33258;&#23450;&#20041;&#26631;&#31614;&#26469;&#35206;&#30422;&#29616;&#26377;&#30340;404&#39029;&#38754;&#24067;&#23616;&#12290;<\/p>\n<h3>&#24635;&#32467;<\/h3>\n<p>&#36890;&#36807;&#19978;&#36848;&#27493;&#39588;&#65292;&#24744;&#24050;&#32463;&#25104;&#21151;&#22320;&#22312;WordPress&#20013;&#23454;&#29616;&#20102;404&#39029;&#38754;&#36861;&#36394;&#21644;&#37325;&#23450;&#21521;&#30340;&#21151;&#33021;&#12290;&#36825;&#20010;&#35299;&#20915;&#26041;&#26696;&#19981;&#20165;&#31616;&#27905;&#26131;&#29992;&#65292;&#32780;&#19988;&#21487;&#20197;&#26681;&#25454;&#24744;&#30340;&#38656;&#27714;&#36827;&#34892;&#20010;&#24615;&#21270;&#35843;&#25972;&#12290;&#24076;&#26395;&#36825;&#20010;&#25945;&#31243;&#23545;&#24744;&#26377;&#25152;&#24110;&#21161;&#65281;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#22312;WordPress&#20013;&#35774;&#32622;404&#38169;&#35823;&#39029;&#38754;&#21644;&#23454;&#29616;&#33258;&#21160;&#37325;&#23450;..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2107,2106],"tuisongtax":[],"class_list":["post-3779","post","type-post","status-publish","format-standard","hentry","category-wpdt","tag-cjyy","tag-cjzn"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/3779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/comments?post=3779"}],"version-history":[{"count":0,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/posts\/3779\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/media?parent=3779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/categories?post=3779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tags?post=3779"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/wpcms\/wp-json\/wp\/v2\/tuisongtax?post=3779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}