So you can do something like this:
- Open the
404.php
file and add these lines to the top of it. If you don’t have one, create it. This will ensure WordPress uses this file for all permalinks that no longer exist or never existed.
<?php
/**
* Template Name: 404 Page
*/
$four_oh_four = get_permalink( get_page_by_path( '404' ) );
wp_redirect( $four_oh_four );
exit();
- Create a page with slug ‘404’.The above code will now redirect from the regular 404 template to a page with ‘404’ slug.
I haven’t tested it but should work.
Optionally, you could also use PHP’s default redirection using headers if you want to. I just used WordPress’ redirection API.
Related Posts:
- How do I redirect the browser to 404 page, if no posts are found in home page
- How to redirect if 404 error in wordpress then redirect 404.php url
- How to force a 404 on WordPress
- How do I skip wordpress’s 404 handling and redirect all 404 errors for static files to 404.html?
- wp_redirect() function is not working
- Redirect page URL to home URL without using a plugin
- How do I programmatically generate a 404?
- WordPress HTTPS redirect loop
- Password change when the user login first time
- How do I skip wordpress’s 404 handling?
- Stop unwanted WP redirection to new url
- wp-login.php — redirect logged in users to custom URL
- Redirecting old site links to new site
- Redirect to login page
- Temporary redirect prevents getting $_POST array
- Creating intro page in wordpress
- URL Redirect and Bulk Actions in wp_list_table
- Using a custom field value to redirect away from a 404 page
- 404 redirection and Google’s index [closed]
- Headers already sent – WordPress core
- Redirect feed to 404 page
- Perform a redirect after user action
- 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]
- How to auto login after registration? [duplicate]
- Deny access to a path (give 403 or 404 response)
- header and wp_redirect not working. cannot modify header information warning
- Code to create a redirection after login?
- How do I redirect /search/ to ?s=
- How to redirect to home page after registration?
- Defining a custom 404 for non-WordPress parts of site
- How to use Regex to add to a url?
- Redirect first category archive page to normal page
- Stuck In a Redirect Loop
- WordPress Auto-Redirecting on 404
- Adding rewrite rule dynamically for search results redirecting to 404 URL
- How to redirect if a background request is still being executed
- Redirect custom post type from one domain to another domain
- I get redirected too many times only in wp-admin?
- Redirect user to previous page after signup from custom form
- Built-In Postname Redirection vs Hard Redirects in relation to SEO and performance
- Get query parameters from external url and make a redirection
- wordpress_redirect returns different headers for HEAD and GET requests
- Show different page for first time user
- Redirect outside WP after login
- HTML Redirect to WP pages
- Why does the $_GET parameter ?search forward the front-page to the archive/blog page
- How to redirect a wrong search on my wordpress website to the error 404 page?
- WP page 404 error only on mobile
- store URL global before we redirect
- Is it possible to wp_redirect() to a new tab?
- Redirect Attachment Page to Attachment
- How to redirect from one WP site to another
- How can I redirect users on the new 404 page without plugin?
- How do I write a subdomain redirect?
- How to redirect an old page url to the homepage
- Dynamic 404 page content while still keeping 404 status code?
- How to fix automatic redirects?
- Redirect to parent page if child does not exist
- Redirect User to login page
- Missing domain http://./wp-… in redirects
- How to redirect non existent pages/posts in wordpress using htaccess
- Redirecting simple big problem
- Redirect Page ID, based on logged-in User Role
- How to Redirect WordPress domain.com/?anyword to 404 Page?
- How to redirect a child page to its parent page?
- WordPress multi domain: page redirect to main domain whenever WordPress do the URL guessing issue
- Applying ‘middleware’ to a url before redirecting? Does WP have built in mechanism for this?
- How can I prevent caching of wp_redirect?
- Debugging issue with redirection in WordPress
- Add base folder to CPT and 301
- How do redirect user back to previous page when on certain pages?
- How do i make WordPress return 404 instead of redirecting on misspelled page?
- Keep the old referrer after failed login
- How to remove redirection
- ERR_TOO_MANY_REDIRECTS when switching from good database to old database
- How to automatically redirect category pages (301) when changing the location of a category in the hierarchy
- Make custom post type archive for administrator only
- How to 301 redirect sub domain post URL to root domain
- Page editing in backend redirecting to 404 page not found with url /post.php
- Disable WordPress URL auto Redirect
- Internal redirect from page to category
- wp_redirect leading to an infinite loop
- How to redirect new registrars to a custom registration page instead of WP default registration page?
- redirect after account activation for forum using bbpress and buddypress
- using wp_rewrite but keep the original url in the address bar
- How do I skip wordpress’s 404 handling?
- How to redirect 404s that generated for css&JS files?
- Force SSL on a single page which is used as iFrame
- Redirect based on $_GET parameters
- 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?
- problem redirecting users to page on login
- Create a 301 Redirect automatically when adding %category% in the permalink
- Other pages fine but wp-admin showing ERR_TOO_MANY_REDIRECTS Error
- Post Migration Site Migration Redirects All Known Solutions Attempted
- Redirect certain 404 pages to parent page