September 21, 2026
Apache .htaccess 404 Redirect Guide
Learn how to use Apache Redirect, RedirectMatch, and mod_rewrite to map old URLs to relevant new destinations without masking every 404.

Apache sites commonly use .htaccess for URL changes, but not every redirect requires the same mechanism.
Use Redirect for simple mappings
When an old path has a clear new destination, a simple permanent redirect is easy to read and maintain.
Redirect 301 /old-page https://example.com/new-pageUse RedirectMatch for predictable patterns
If many old URLs follow a consistent structure, RedirectMatch can use regex to map them. Test broad patterns carefully to avoid catching unrelated requests.
Use mod_rewrite for complex conditions
RewriteRule and RewriteCond are useful when redirects depend on query strings, request conditions, or more complex path transformations.
Example:
RewriteEngine On
RewriteRule ^old-page$ /new-page [R=301,L]Rule order matters. A broad rule can override a more precise mapping if placed too early.
A custom 404 is not the same as a redirect
Apache can serve a custom error document for 404 responses. That improves the user experience but should not turn a truly missing URL into a successful page response.
Avoid homepage-wide redirects
If /products/old-watch has a direct replacement, redirecting it makes sense. If a random path has no related content, sending it to the homepage does not create relevance.
Manage growth carefully
Large migration projects can create hundreds or thousands of lines in .htaccess. As the redirect set grows, consider grouping rules, moving logic to a more appropriate configuration layer, or using a dedicated redirect system.
How no404 helps
no404 surfaces real 404 requests so teams can prioritize the old URLs that still matter instead of adding speculative rules for every possible path.
Conclusion
Use Redirect for simple mappings, RedirectMatch for patterns, and mod_rewrite for complex conditional logic. Redirect only when a meaningful replacement exists; otherwise preserve a true error response.