UX & Technical SEO

How to redirect users instead of hitting a 404 error

Tired of visitors hitting dead ends? This practical guide shows you how (and when) to redirect 404 pages using WordPress snippets, plugins, Apache .htaccess, and Nginx.

Dean Davis
Dean DavisWeb Designer in Basingstoke
July 26, 20257 min read
How to redirect users instead of hitting a 404 error - Dean Davis

Ever clicked a link, expecting something useful, and landed on a plain “404 Not Found” page? It’s like showing up to a shop and finding the door locked. That’s how your visitors feel, too. Instead of letting them bounce immediately back to Google, you can gracefully send them back to your homepage or a relevant alternative. Quick fix. Big difference.

1Why Redirect Missing Pages to Your Homepage?

1. Keeps Visitors On Your Site

People hate dead ends. When visitors encounter a broken link, redirecting them to your homepage gives them an opportunity to explore other services or articles rather than clicking away.

2. Helps Lower Bounce Rates & Maintain Crawling

While not a magic SEO fix, redirecting ensures search engine bots keep discovering live internal links rather than hitting broken halts.

3. Polished Business Presentation

A bare server 404 message looks unfinished. Handling missing links smoothly makes your digital presence feel carefully maintained.

2How to Set Up 404 Redirects

WordPress (No Plugins — functions.php Snippet)

Add this lightweight function to your child theme's functions.php file:

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

Apache Server (.htaccess)

If your site runs on an Apache web server, place this single directive inside your root .htaccess file:

ErrorDocument 404 /

Nginx Server Configuration

For high-performance Nginx servers, add the following inside your server block:

error_page 404 = @fallback;

location @fallback {
    return 301 /;
}

3When NOT to Redirect Everything to the Homepage

While redirecting missing pages is helpful, doing it blindly can cause UX and SEO issues:

Avoid Soft 404s

If an old URL had significant backlinks, redirecting it to an unrelated homepage might cause Google to flag it as a Soft 404 and ignore link equity.

Target Relevant Replacements First

If a specific service or product URL was renamed, always 301 redirect to the new version of that specific page rather than dumping visitors onto the homepage.

Closing a Website or Service?

If you are shutting down a store or project with hundreds of legacy URLs indexed in Google, point a single wildcard redirect rule to your homepage displaying a clear farewell message: “This business is now closed. Thank you for your support.” This keeps your brand tidy without maintaining obsolete catalog pages.

The Bottom Line

A generic 404 error is like a cold shrug. A thoughtful redirect is like saying, “That page isn't here anymore, but come check out what else we have!” Use homepage redirects as a safety net, pair them with direct 301s for moved pages, and keep your user experience seamless.

Dean Davis
Written By

Dean Davis

Freelance web designer in Basingstoke crafting resilient websites, fixing broken redirect flows, and keeping user journeys friction-free.

Need assistance fixing broken website links? Let's talk
Website Health & Maintenance

Eliminate broken links and dead ends

Upgrade your website with proper 301 redirects, high speed, and bespoke design from Basingstoke.

Start Your Project