{"id":7621,"date":"2026-04-14T13:53:54","date_gmt":"2026-04-14T11:53:54","guid":{"rendered":"https:\/\/mybox.com\/help\/?post_type=manual_kb&#038;p=7621"},"modified":"2026-06-08T09:47:55","modified_gmt":"2026-06-08T07:47:55","slug":"wordpress-how-to-redirect-404-to-home-page-in-htaccess","status":"publish","type":"manual_kb","link":"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-how-to-redirect-404-to-home-page-in-htaccess\/","title":{"rendered":"WordPress: How to Redirect 404 to Home Page in .htaccess"},"content":{"rendered":"\n<div class=\"translation-block translation-block-merged\">\n<p class=\"wp-block-paragraph\">In 2026, maintaining a seamless user experience on your <strong>mybox<\/strong> server is vital. When a visitor hits a &#8220;Page Not Found&#8221; error, redirecting them to the homepage can keep them on your site. However, doing this via the <code>.htaccess<\/code> file requires precision to avoid breaking WordPress core functions like the REST API or the admin dashboard.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-how-to-redirect-404-to-home-page-in-htaccess\/#Requirements_and_Backup\" >Requirements and Backup<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-how-to-redirect-404-to-home-page-in-htaccess\/#Where_to_Insert_Rules_in_htaccess\" >Where to Insert Rules in .htaccess<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-how-to-redirect-404-to-home-page-in-htaccess\/#The_Safest_Redirect_Script_with_Exceptions\" >The Safest Redirect Script (with Exceptions)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-how-to-redirect-404-to-home-page-in-htaccess\/#301_vs_302_Which_Should_You_Use\" >301 vs. 302: Which Should You Use?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-how-to-redirect-404-to-home-page-in-htaccess\/#SEO_Note_and_Best_Practices\" >SEO Note and Best Practices<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/wordpress-how-to-redirect-404-to-home-page-in-htaccess\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Requirements_and_Backup\"><\/span>Requirements and Backup<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before touching your configuration, perform these safety steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Backup:<\/strong> Download your current <code>.htaccess<\/code> file via FTP.<\/li>\n\n\n\n<li><strong>Server Check:<\/strong> Ensure your server is running <strong>Apache<\/strong> (Standard on mybox) and that <code>mod_rewrite<\/code> is active.<\/li>\n\n\n\n<li><strong>Text Editor:<\/strong> Use a plain text editor (like Notepad++ or VS Code) to avoid adding hidden formatting characters.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_to_Insert_Rules_in_htaccess\"><\/span>Where to Insert Rules in .htaccess<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<\/div>\n\n<div id=\"mybox-1437776596\" class=\"mybox-content mybox-entity-placement\"><div class=\"early-access-banner-inpost\">\r\n  <div class=\"banner-left-inpost\">\r\n    <div class=\"icon-box-inpost\">\r\n      <img decoding=\"async\" src=\"https:\/\/mybox.com\/help\/wp-content\/uploads\/2026\/02\/square-info-icon.svg\" alt=\"Info\">\r\n    <\/div>\r\n    <div class=\"text-box-inpost\">\r\n      <span class=\"label-inpost\"><span class=\"translation-block translation-block-banner-text\">Early access<\/span><\/span>\r\n      <h4><span class=\"translation-block translation-block-banner-text\">Still need help?<\/span><\/h4>\r\n      <p><span class=\"translation-block translation-block-banner-text\">Contact our customer service team.<\/span><\/p>\r\n    <\/div>\r\n  <\/div>\r\n\r\n  <div class=\"banner-right-inpost\">\r\n    <a href=\"https:\/\/panel.mybox.com\/helpdesk2\/v\/list\/\" class=\"banner-button-inpost\"><span class=\"translation-block translation-block-banner-text\">Message us<\/span><\/a>\r\n  <\/div>\r\n<\/div><\/div>\n\n<div class=\"translation-block translation-block-merged\"><p class=\"wp-block-paragraph\">WordPress automatically manages the code between <code># BEGIN WordPress<\/code> and <code># END WordPress<\/code>. <strong>Never place your custom rules inside this block<\/strong>, as WordPress will overwrite them during updates.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Place your code at the very top of the file:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># CUSTOM 404 REDIRECT START\n&lt;IfModule mod_rewrite.c&gt;\nRewriteEngine On\n# Your rules go here\n&lt;\/IfModule&gt;\n# CUSTOM 404 REDIRECT END\n\n# BEGIN WordPress\n... existing code ...\n# END WordPress\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_Safest_Redirect_Script_with_Exceptions\"><\/span>The Safest Redirect Script (with Exceptions)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A &#8220;blind&#8221; redirect can break your site&#8217;s ability to log in or update. Use this version, which includes 2026-standard exceptions for the <strong>WordPress REST API<\/strong>, <strong>Sitemaps<\/strong>, and <strong>Admin panels<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apache<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;IfModule mod_rewrite.c&gt;\nRewriteEngine On\nRewriteBase \/\n\n# 1. Do not redirect the homepage itself (prevents loops)\nRewriteCond %{REQUEST_URI} !^\/$\n\n# 2. Exclude Admin and Login areas\nRewriteCond %{REQUEST_URI} !^\/wp-admin &#91;NC]\nRewriteCond %{REQUEST_URI} !^\/wp-login\\.php &#91;NC]\n\n# 3. Exclude REST API and Feeds (Critical for blocks\/plugins)\nRewriteCond %{REQUEST_URI} !^\/wp-json &#91;NC]\nRewriteCond %{REQUEST_URI} !\/feed\/?$ &#91;NC]\n\n# 4. Exclude Sitemap and Robots.txt (Crucial for SEO)\nRewriteCond %{REQUEST_URI} !sitemap &#91;NC]\nRewriteCond %{REQUEST_URI} !robots\\.txt &#91;NC]\n\n# 5. Only redirect if the file or directory actually DOES NOT exist\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\n\n# 6. Perform the 301 (Permanent) Redirect to homepage\nRewriteRule ^.+$ \/ &#91;R=301,L]\n&lt;\/IfModule&gt;\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"301_vs_302_Which_Should_You_Use\"><\/span>301 vs. 302: Which Should You Use?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>301 (Permanent):<\/strong> Tells Google the old page is gone forever and the homepage is the new destination. Use this once you are sure the code works.<\/li>\n\n\n\n<li><strong>302 (Temporary):<\/strong> Use this for testing. Browsers won&#8217;t &#8220;cache&#8221; a 302, so if you make a mistake, it&#8217;s easier to fix without clearing your visitors&#8217; browser history.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SEO_Note_and_Best_Practices\"><\/span>SEO Note and Best Practices<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">While a 404-to-home redirect is &#8220;clean,&#8221; Google often treats these as <strong>&#8220;Soft 404s.&#8221;<\/strong> This means Google knows the page is missing and may not pass the &#8220;SEO juice&#8221; of the old link to your homepage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Better Alternative:<\/strong> If you deleted a specific page (e.g., <code>old-product<\/code>), it is better to redirect that specific URL to a <em>similar<\/em> current product rather than the generic homepage. Use a 404-to-home redirect only as a &#8220;catch-all&#8221; for random mistyped URLs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Redirecting 404s via <code>.htaccess<\/code> is the fastest method because it happens at the server level before WordPress even loads. By using the &#8220;Exceptions&#8221; version of the script, you ensure your site remains fast and functional while keeping lost visitors engaged on your homepage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"template":"","format":"standard","manualknowledgebasecat":[25],"manual_kb_tag":[190,716,780,1321,1626,2612,4871,9745,9746,9747],"class_list":["post-7621","manual_kb","type-manual_kb","status-publish","format-standard","hentry","manualknowledgebasecat-hosting","manual_kb_tag-wordpress","manual_kb_tag-page-not-found","manual_kb_tag-apache-server","manual_kb_tag-rewrite-engine","manual_kb_tag-htaccess","manual_kb_tag-mod-rewrite","manual_kb_tag-30-redirect","manual_kb_tag-redirect-40-to-homepage","manual_kb_tag-redirect-to-homepage","manual_kb_tag-soft-40"],"_links":{"self":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/7621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":3,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/7621\/revisions"}],"predecessor-version":[{"id":7622,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/7621\/revisions\/7622"}],"wp:attachment":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/media?parent=7621"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manualknowledgebasecat?post=7621"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb_tag?post=7621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}