When a user visits a non-existent page on your WordPress site, they encounter a 404 error page. This is bad for user experience and SEO, as it can increase the bounce rate and reduce search rankings.
The best solution is to redirect the 404 page to a relevant page on your website. Many people use plugins for this, but you can do it manually without installing extra plugins.
In this guide, I will explain how to redirect a 404 page in WordPress without using any plugin.
Why Redirect 404 Pages?
A 404 error occurs when a requested page does not exist. Redirecting these pages helps in:
- Improving user experience – Users will be directed to a useful page instead of a dead-end.
- Boosting SEO – Search engines prefer websites with fewer broken links.
- Reducing bounce rate – Visitors stay longer on your website.
- Fixing deleted or moved pages – If you delete a page, you can redirect users to a similar page.
Method 1: Redirect 404 to Home Page via .htaccess
The .htaccess
file is a configuration file used by Apache servers. You can use it to set up automatic redirection.
Steps to Redirect 404 to Homepage Using .htaccess
- Access Your WordPress Files
- Use an FTP client (like FileZilla) or cPanel File Manager to access your website files.
- Locate the .htaccess File
- The
.htaccess
file is found in the root directory of your WordPress installation. - If you don’t see it, enable “Show Hidden Files” in your file manager.
- Edit the .htaccess File
- Right-click on
.htaccess
and choose Edit.
- Add the Following Code at the End:
ErrorDocument 404 /index.php
- This redirects all 404 pages to the homepage (
index.php
).
- Save the File and Check
- Visit a non-existent page on your website (e.g.,
yoursite.com/randompage
). - It should now redirect to the homepage.
Read also: How to Fix Too Many Redirects in Chrome: Complete Guide
Method 2: Redirect 404 to Any Page Using functions.php
If you want more control over redirection, you can modify the functions.php file in your theme.
Steps to Redirect 404 to Any Page Using functions.php
- Go to Your WordPress Theme Editor
- Login to your WordPress dashboard.
- Navigate to Appearance > Theme File Editor.
- Open the
functions.php
file.
- Add the Following Code at the End:
function redirect_404_to_homepage() {
if (is_404()) {
wp_redirect(home_url());
exit();
}
}
add_action('template_redirect', 'redirect_404_to_homepage');
- This function checks if a 404 error occurs and redirects users to the homepage.
- Save Changes and Test
- Open a non-existing page and check if it redirects properly.
💡 Tip: If you want to redirect users to a different page (not the homepage), replace home_url()
with the desired URL:
wp_redirect('https://yoursite.com/custom-page');
Method 3: Custom 404 Page Using 404.php
Another approach is creating a custom 404.php file to guide users instead of redirecting them.
Steps to Create a Custom 404 Page
- Go to Your WordPress Theme Folder
- Use FTP or File Manager and navigate to
wp-content/themes/your-theme/
.
- Find the 404.php File
- If it exists, edit it. If not, create a new
404.php
file.
- Add the Following Code:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . home_url());
exit();
?>
- This redirects all 404 errors to the homepage.
- Save the File and Test
- Visit any broken link to check the redirection.
Which Method Should You Use?
- Use .htaccess if you want a server-level redirection (better performance).
- Use functions.php if you prefer a WordPress-friendly solution.
- Use 404.php if you want a custom 404 page while also redirecting visitors.
You’ll also like to read:
- Want to Rank Higher on Google? Try These 10 Methods
- Are you struggling to get ranked fast?
- How to Fix: Chrome DNS Cache Not Showing
- Simple Steps to Permanently Delete a Page in Microsoft Word
Final Thoughts
Redirecting 404 pages without a plugin is easy and improves SEO and user experience. Choose the method that best suits your needs. If you are comfortable editing files, .htaccess
is the best option. Otherwise, using functions.php is a safe alternative.
Thank you for reading! 😊 I hope this guide helped you understand how to redirect 404 pages in WordPress without using a plugin.
If you have any questions or need further clarification, feel free to ask in the comments below. I’d love to hear your thoughts! 💬👇
I blog frequently and I genuinely appreciate your information. This article has truly peaked my interest.
I’m going to bookmark your site and keep checking for new details about once per week.
I subscribed to your Feed as well.
Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to more added agreeable from you! By the way, how could we communicate?
Μagnificent goods from you, man. I’ve undеrstand
your stuff previous to and you’re just too magnificent.
I actually like what you’ѵe acquired here, ϲertainly like what you ɑre stating and the way in ѡhich you say it.
You make it enjoyable and you still take care of to keep it
wise. I can not wzit t᧐ reаd far more from you. This is really a wonderful web
site.
my site :: Berita Viral Terupdate Saat Ini