{"id":253,"date":"2012-10-06T12:21:21","date_gmt":"2012-10-06T12:21:21","guid":{"rendered":"http:\/\/pixert.com\/blog\/?p=253"},"modified":"2021-04-03T04:16:41","modified_gmt":"2021-04-03T04:16:41","slug":"how-to-301-redirect-all-404-error-pages-to-homepage-in-wordpress","status":"publish","type":"post","link":"https:\/\/pixert.com\/blog\/how-to-301-redirect-all-404-error-pages-to-homepage-in-wordpress\/","title":{"rendered":"How to 301 Redirect All 404 Error Pages to Homepage in WordPress"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"68\" data-attachment-id=\"25\" data-permalink=\"https:\/\/pixert.com\/blog\/how-to-upgrade-wordpress\/wordpresslogo\/\" data-orig-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?fit=498%2C113&amp;ssl=1\" data-orig-size=\"498,113\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"WordPress &#8211; the logo\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?fit=300%2C68&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?fit=498%2C113&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo-300x68.png?resize=300%2C68\" alt=\"\" class=\"wp-image-25\" title=\"WordPress - the logo\" srcset=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?resize=300%2C68&amp;ssl=1 300w, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?w=498&amp;ssl=1 498w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>404 Not Found errors are generated when users follow broken\/dead links. \u00a0You\u2019d be amazed how many 404 errors even the best websites have. \u00a0The quickest fix is to redirect your 404 errors to your home page. Almost every theme that you use with your self hosted WordPress Blog have an inbuilt 404 Page (404.php), which you can\u00a0customize\u00a0as per your site\/blog requirements<\/p>\n\n\n\n<p>Two advantages we get when we are using this method<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Search Engine Ranking will not be affected in any way, as we are using 301 Permanent Redirection here<\/li><li>The above trick will actually remove ALL exiting 404 Not Found Errors from Google Webmasters Tools and Bing Webmasters<\/li><\/ul>\n\n\n\n<p>1. Find 404.php in the activated theme, e.g Twenty Eleven (wp-content\/themes\/twentyeleven)<\/p>\n\n\n\n<p>&#8211; Backup 404.php<\/p>\n\n\n\n<p>&#8211;&nbsp;Login to your WordPress Dashboard and head over to&nbsp;<strong>Appearance &gt; Editor<\/strong>.<\/p>\n\n\n\n<p>&#8211; Click 404 Template (404.php) to open it in Editor windw<\/p>\n\n\n\n<p>&#8211;\u00a0Delete all code in 404.php file and\u00a0enter following lines of code in it:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: Code Block; notranslate\" title=\"Code Block\">\nheader(\"HTTP\/1.1 301 Moved Permanently\"); header(\"Location: \".get_bloginfo('url')); exit(); \n<\/pre><\/div>\n\n\n<p>&#8211; Hit the Update File Button<\/p>\n\n\n\n<p>2. Some themes don&#8217;t have 404 Template file or 404.php<\/p>\n\n\n\n<p>&#8211; Create 404.php with Text Editor, e.h Notepad++<\/p>\n\n\n\n<p>&#8211; Add the following code<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: Code Block; notranslate\" title=\"Code Block\">\nheader(\"HTTP\/1.1 301 Moved Permanently\"); header(\"Location: \".get_bloginfo('url')); exit();\n<\/pre><\/div>\n\n\n<p>&#8211; Upload this new 404.php to theme directory<\/p>\n","protected":false},"excerpt":{"rendered":"<p>404 Not Found errors are generated when users follow broken\/dead links. \u00a0You\u2019d be amazed how many 404 errors even the best websites have. \u00a0The quickest fix is to redirect your 404 errors to your home page. Almost every theme that you use with your self hosted WordPress Blog have an inbuilt 404 Page (404.php), which [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[6],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-wordpress","tag-wordpress-2"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1pvi1-45","jetpack-related-posts":[{"id":578,"url":"https:\/\/pixert.com\/blog\/why-i-do-not-need-rss-feed-on-my-wordpress-blog\/","url_meta":{"origin":253,"position":0},"title":"Why I do not need RSS Feed on my WordPress blog, How to disable it","author":"Pixel Insert \/ Pixert","date":"March 24, 2021","format":false,"excerpt":"One of the problems I found is the number of links with feeds in my blog that are crawled, not indexed by Google. Frankly I don't know how many subscribed to my blog feed. And it feels less effective using RSS feed. For that I decided that I do not\u2026","rel":"","context":"In &quot;WordPress&quot;","block_context":{"text":"WordPress","link":"https:\/\/pixert.com\/blog\/category\/wordpress\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2021\/03\/0C834D4A-B347-40D3-B941-BCC9B1418764.jpeg?fit=960%2C1200&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2021\/03\/0C834D4A-B347-40D3-B941-BCC9B1418764.jpeg?fit=960%2C1200&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2021\/03\/0C834D4A-B347-40D3-B941-BCC9B1418764.jpeg?fit=960%2C1200&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2021\/03\/0C834D4A-B347-40D3-B941-BCC9B1418764.jpeg?fit=960%2C1200&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":149,"url":"https:\/\/pixert.com\/blog\/redirect-https-to-http-on-your-site-with-htaccess\/","url_meta":{"origin":253,"position":1},"title":"Redirect https to http on your site with .htaccess","author":"Pixel Insert \/ Pixert","date":"October 19, 2011","format":false,"excerpt":"You can use the following snippet to avoid having duplicate listings in the search engines or when your site showing security errors on your browser","rel":"","context":"In &quot;CentOS&quot;","block_context":{"text":"CentOS","link":"https:\/\/pixert.com\/blog\/category\/centos\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/cpanel-logo.gif?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":254,"url":"https:\/\/pixert.com\/blog\/redirect-old-domain-to-new-domain\/","url_meta":{"origin":253,"position":2},"title":"Redirect Old Domain to New Domain","author":"Pixel Insert \/ Pixert","date":"July 14, 2012","format":false,"excerpt":"How to redirect old domain to new domain through .htaccess? You should add this code in .htaccess file Method no 1 Method no 2","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":195,"url":"https:\/\/pixert.com\/blog\/redirect-certain-pages-from-http-to-https-with-htaccess\/","url_meta":{"origin":253,"position":3},"title":"Redirect certain pages from http to https with .htaccess","author":"Pixel Insert \/ Pixert","date":"February 10, 2012","format":false,"excerpt":"The following trick is useful for E-Commerce sites. \u00a0We only need few pages redirected to https to secure transaction This will automatically rewrite the url to https as long as the page is not already an https link. This conditional keeps it from causing a loop. It's very handy to\u2026","rel":"","context":"In &quot;WordPress&quot;","block_context":{"text":"WordPress","link":"https:\/\/pixert.com\/blog\/category\/wordpress\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo-300x68.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":163,"url":"https:\/\/pixert.com\/blog\/moving-wordpress-blog-from-a-subdomain-to-a-subfolder\/","url_meta":{"origin":253,"position":4},"title":"Moving WordPress blog from a subdomain to a subfolder","author":"Pixel Insert \/ Pixert","date":"November 25, 2011","format":false,"excerpt":"I had this blog and this main site on same domain, pixert.com a year ago. I got high traffic to same domain. I separated the blog from main site after serious problems occurred. I made pixert.com\/blog for blog and pixert.com for main site That's a mistake I should \u00a0not done.\u2026","rel":"","context":"In &quot;cPanel&quot;","block_context":{"text":"cPanel","link":"https:\/\/pixert.com\/blog\/category\/cpanel\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo-300x68.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":145,"url":"https:\/\/pixert.com\/blog\/refresh-local-computer-dns-cache\/","url_meta":{"origin":253,"position":5},"title":"Refresh Local Computer DNS Cache","author":"Pixel Insert \/ Pixert","date":"October 17, 2011","format":false,"excerpt":"We should update DNS records after we had registered a domain name and did setup web hosting for that domain. DNS is heavily cached and changes could take up to 24 hours to take effect. It is recommended you wait this long after the initial set-up before troubleshooting any errors.\u2026","rel":"","context":"In &quot;Mac OS&quot;","block_context":{"text":"Mac OS","link":"https:\/\/pixert.com\/blog\/category\/mac-os\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/10\/mac-os-150x150.jpg?resize=350%2C200","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":0,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"wp:attachment":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}