Connect with Codesitez for web development and SEO services. We are ready to help you.

Phone/WhatsApp

+3257753840

Social Links

SEO

How to fix error 404 not found – WordPress, Shopify & .htaccess

404 page not found error solution. Step-by-Step Guide to redirect 404 error to home page or any other page.

How to fix error 404 not found – WordPress, Shopify & .htaccess

404 Page Redirect: Easy and Simple Method

If any page of your website is deleted or its link is changed, users will get "404 Page Not Found" error. This doesn't seem like good! This means that we redirect users to the home page or some other page. Come on, let's see the easy steps!

What is 404 Page and why is Redirect necessary?

Whenever a visitor does not find any page of your website, the browser shows "404 Page Not Found" error. This error tab comes up:

  • The page has been deleted.
  • The URL of the page has changed
  • Have you written a wrong link?
  • Is there any issue on the server?

If users get this error, they leave the website hacked, which is bad for both SEO and user experience. Its best feature is that users are automatically redirected to the home page or any other relevant page.

Method to redirect 404 page

  • WordPress (without plugins) – If your website is on WordPress
  • Shopify Settings – If your site is on Shopify
  • .htaccess File – If your server is Apache

1. How to Fix WordPress 404 Not Found Error without plugin

If your website is on WordPress, you can redirect even without a plugin. Its method is very easy.

Steps:

  1. Open the “404.php” file of WordPress theme.
  2. Add this code in it:
<?php
wp_redirect(home_url());
exit();
?>

This will redirect 404 page to home page. If you want to send to any other page then write the URL of that page instead of home_url().

Alternative method(From Functions.php)

If you want to add code to functions.php file, you can also use this method:

function redirect_404_to_home() {
    if (is_404()) {
        wp_redirect(home_url());
        exit();
    }
}
add_action('template_redirect', 'redirect_404_to_home');

This method will send every 404 page to the home page, without editing the "404.php" file.

2. Fix Shopify 404 Not Found Error

If your website is on Shopify, you can redirect it from the admin panel. Shopify's built-in redirect system is very easy.

Steps:

  1. Login to Shopify Admin Panel.
  2. Go to "Online Store" > "Navigation" > "URL Redirects".
  3. Click on "Create URL Redirect" button.
  4. Write down "Old URL" (which is giving 404 error) and "New URL" (where to send).
  5. "Save". Done!

🔹 Example: If your old page /old-page has been deleted, set to redirect /old-page → /new-page.

📌 Shopify does not have an automatic redirect system, so you have to fix every broken link manually.

3. Fix 404 Page Not Found Error from .htaccess file (If the server is Apache)

If your server is Apache, you can redirect 404 errors to home or some other page by adding redirect code to the .htaccess file.

Steps:

  1. Open the .htaccess file (this file is in the root folder of your website).
  2. Add this code to it:
ErrorDocument 404 /index.html

This will redirect 404 errors to home page.

🔹 If you want to send to any other page then write the URL of that page instead of index.html.

Alternative Method: 301 Redirect

If you want to permanently redirect your broken link, add this code:

Redirect 301 /404.html /page-name

For temporary redirect your broken link, add this code:

Redirect 302 /404.html /page-name

This will set a permanent redirect, which is better for SEO.

If you want to redirect all URLs on your website to HomePage, you can add the following code to the .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^(.*)$ / [R=301,L]

This code will permanently redirect every URL to homepage (/). R=301 means Permanent Redirect.

There is no need for domain name in this code, because it just redirects the URLs of the websites on your server. If you have uploaded your .htaccess file to the root folder of your website, this code will redirect all URLs of your domain to the homepage.

If you want the domain name to be displayed explicitly, you can modify the code a bit, like this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^(.*)$ http://www.yourdomain.com/ [R=301,L]

Here replace http://www.yourdomain.com/ with your actual domain name.

Which method is better?

WordPress users: Use wp_redirect() or functions.php method instead of plugins. 

Shopify users: Use "URL Redirects" settings. 

Apache server users: Use .htaccess file.

📌 Best Practice: Fix every broken link manually so that users get better experience and SEO ranking improves.

 

4 min read
Jan 30, 2025
By Ghazi Admin
Share

Leave a comment

Your email address will not be published. Required fields are marked *

Related posts

Feb 11, 2025 • 3 min read
Will AI Content Rank in Google or Not? Know the Truth!

Can AI-Written Content Rank in Google? Learn the Real Facts, Google Policy.