You can use this code inside your 404.php template file to safely redirect to users to homepage:
wp_safe_redirect(site_url());
exit();
Use this code before every line of code in your 404.php. This will redirect everyone who visits the 404 page to the website’s home URL, which would be what you are looking for.
You don’t have to delete the content of your 404.php file, since every line of code after the exit() will be ignored.
Related Posts:
- How to force a 404 on WordPress
- Redirect Restricted Page to 404
- How to prevent automatic redirection of 404 errors and “incorrect” URLs?
- How do I skip wordpress’s 404 handling and redirect all 404 errors for static files to 404.html?
- How do I programmatically generate a 404?
- How do I skip wordpress’s 404 handling?
- 404 redirection and Google’s index [closed]
- Redirect feed to 404 page
- Check if post is in draft or pending review?
- Why specific file directory fails to redirect but its parent folder succeeds?
- WordPress blocking/preventing viewing of .cgi file in subdirectory [closed]
- Deny access to a path (give 403 or 404 response)
- Redirect a page id url but not the page slug
- Defining a custom 404 for non-WordPress parts of site
- WordPress Auto-Redirecting on 404
- Built-In Postname Redirection vs Hard Redirects in relation to SEO and performance
- How to redirect a wrong search on my wordpress website to the error 404 page?
- WP page 404 error only on mobile
- Force 404 redirect to home?
- How can I redirect users on the new 404 page without plugin?
- How to redirect an old page url to the homepage
- Dynamic 404 page content while still keeping 404 status code?
- Redirect to parent page if child does not exist
- How to redirect non existent pages/posts in wordpress using htaccess
- How to Redirect WordPress domain.com/?anyword to 404 Page?
- How do I redirect the browser to 404 page, if no posts are found in home page
- How do i make WordPress return 404 instead of redirecting on misspelled page?
- How to redirect if 404 error in wordpress then redirect 404.php url
- Redirect to /404/
- Page editing in backend redirecting to 404 page not found with url /post.php
- How do I skip wordpress’s 404 handling?
- Subpages return 404 server error
- WordPress subfolders htaccess bypassing the root htaccess RewriteRule
- Why my htacess rewrite return 404?
- How to Redirect Url to homepage?
- Stopping media file redirects
- Forcing header cache control in 404 pages
- redirect to 404 page
- Redirect certain 404 pages to parent page
- Redirect of specific words in URL ahead of website migration
- Why am I getting a 301 on a existing post?
- Custom login form redirect to external site
- Clarification on auth_redirect()
- Exclude a path from WordPress using .htaccess redirects (Apache)
- Stop unwanted WP redirection to new url
- Problem to redirect custom page using htaccess
- Website redirecting to old domain name
- How to do 301 redirect to Sub page using htaccess file?
- Redirect guest if he tries to access a specific page
- Localhost wordpress site redirects to public site
- Redirect homepage ( www.sitename.com ) to the latest post
- How to redirect URL with subfolder to the same URL but without subfolder?
- If User is NOT Logged in and Page ID is not 6 – Redirect to Login
- Front end user creation form! How do you keep the user on the same page in event of error?
- How to redirect if a background request is still being executed
- WP site in infinite redirect loop
- WordPress keeps redirecting subpages without http to https homepage after switch
- Redirect non-existent subpages to second part of url
- How to remove the [L] Flag for WordPress index .php mod_rewrite
- ReDirect subfolder link to another sub-folder and force SSL
- How do I remove the RSS Feed Redirect?
- Problem in disabling canonical 301 redirect
- How to redirect just one or two blog posts correctly?
- Why does the $_GET parameter ?search forward the front-page to the archive/blog page
- How to redirect only 404 pages with htaccess in WordPress
- How to redirect the frontend of a WordPress site (only)?
- My site is being redirected to itself
- Permalinks do not include www subdomain
- Front page is being directed to an unknown site
- Domain redirect to wp-admin/setup-config.php file
- After retrive password, redirect to index page
- Change Category Slug Redirection
- WordPress redirect to new domain name
- Blog post is redirecting to home page
- Trying to re-direct users to specific page based on an ACF variable
- Bulk redirect all post
- Disable redirect to homepage after successful Login, Stay on Current Page
- WordPress no permission redirection to a popup
- How force WordPress redirect to current custom page after login
- How to remove redirection
- Site using static homepage, redirects (301) and removes pluses from query string
- Unusual Apache2 Error Causing WordPress Redirect Error?
- Redirect error after updating WordPress to 5.4.2
- 301 Redirect Loop www to non-www – Nginx + Apache2
- how to redirect 404 to attachment.php?
- 301 Redirect in WordPress not working in htaccess
- redirect to https://my-site/wp-admin/ instead of https://my-site/wordpress/wp-admin/ after options updating
- Redirect after login when WordPress in subdirectory
- Redirect after Permalink change – What regex do I use?
- Configure WordPress to listen on a port other than 80
- Do I need to keep the original page when 301 redirecting to a new one?
- Logging back into WordPress after logging out and having issues with ‘loggedout=true’ in redirect URL
- Moving an ASP Site to WordPress – Looking for Help on Redirects
- Rewrite Rule working different than expected
- Redirect to Homepage if URL contains string
- How to redirect to a page after submitting form data?
- How to setup an automatic redirect for when there has been a critical error on the site?
- How to force HTTP and stop SSL completey on WordPress website
- How to Setup 2 Domains on a Single WordPress (Regions Filter)?
- WordPress keeps redirecting to root site after saving any setting