How to Fix Magento 404 Errors
A 404 Not Found error occurs when a requested URL cannot be found by the web server or Magento application. In a Magento store, 404 errors can affect product pages, categories, CMS pages, images, JavaScript files, CSS assets, or even the Magento Admin panel.
A single 404 may simply mean that a page no longer exists. However, widespread 404 errors can indicate problems with URL rewrites, Magento configuration, indexers, web-server rules, static files, caching, extensions, or an incorrect document root.
This guide explains the most common causes of Magento 404 errors and provides practical steps to diagnose and fix them.
What Is a Magento 404 Error?
A 404 error means the requested resource could not be found.
For example:
https://example.com/products/example-product
may return:
404 Not Found
The problem can occur at several levels:
- Magento URL rewrites
- Product or category configuration
- Store view configuration
.htaccess- Nginx configuration
- Incorrect document root
- Missing static files
- Incorrect Base URL
- Cache
- Indexers
- Custom extensions
- Deleted products or categories
- Incorrect permissions
- CDN or reverse-proxy configuration
The first task is to determine what type of URL is returning 404.
Common Types of Magento 404 Errors
Magento 404 problems usually fall into several categories.
Product URL returns 404
Example:
/catalog/product-name
Category URL returns 404
Example:
/category/shoes
CMS page returns 404
Example:
/about-us
CSS or JavaScript returns 404
For example:
/pub/static/frontend/...
Images return 404
For example:
/media/catalog/product/...
Admin URL returns 404
The Magento Admin login page cannot be accessed.
Every Magento page returns 404
This usually points to a server configuration, document-root, rewrite, or Magento routing problem.
1. Determine Whether the 404 Comes From Magento or the Web Server
Before changing anything, determine where the 404 is generated.
Open the affected URL and inspect the response using:
curl -I https://example.com/example-page
You may receive:
HTTP/2 404
Check the response headers and page appearance.
A Magento-generated 404 often has the site’s normal Magento layout.
A web-server-generated 404 may display a generic Nginx or Apache error page.
This distinction helps narrow the problem.
2. Check Whether the Product or Category Exists
If only a specific product returns 404, first verify that the product still exists.
Go to:
Admin Panel → Catalog → Products
Search for the product.
Check:
- Product status
- Visibility
- Website assignment
- Store view assignment
- Product URL Key
- Stock configuration
- Category assignment
A product may exist in the Admin Panel but still not appear correctly on the storefront if it is disabled or not assigned to the appropriate website.
For categories, go to:
Catalog → Categories
Confirm that the category exists and is enabled.
3. Check Product Visibility
Magento products have different visibility settings.
Common options include:
- Not Visible Individually
- Catalog
- Search
- Catalog, Search
If a product is configured as:
Not Visible Individually
its direct product URL may not behave as expected.
For a normal standalone product, verify that the appropriate visibility setting is selected.
Save the product and clear the cache afterward.
4. Check the Product URL Key
Open:
Catalog → Products → Edit Product
Expand the Search Engine Optimization section.
Check the URL Key.
For example:
blue-running-shoes
The resulting URL might be:
https://example.com/blue-running-shoes.html
depending on your Magento configuration.
Avoid unnecessarily changing URL keys on established stores because doing so can create additional broken links.
If you do change a URL key, create or verify the appropriate URL rewrite.
5. Check Magento URL Rewrites
Magento uses URL rewrites to map friendly URLs to internal entities.
Go to:
Marketing → SEO & Search → URL Rewrites
Search for the affected URL.
You may find a rewrite similar to:
Request Path:
blue-running-shoes.html
Target Path:
catalog/product/view/id/123
If the rewrite is missing or incorrect, the storefront may return a 404.
Check:
- Request Path
- Target Path
- Store View
- Redirect Type
- Redirect URL
Be careful when manually creating rewrites because an incorrect target can create another broken URL.
6. Regenerate Product and Category URLs
Magento’s indexers are responsible for maintaining several pieces of catalog-related data.
Check indexer status:
php bin/magento indexer:status
If an indexer is invalid, run:
php bin/magento indexer:reindex
Then flush the cache:
php bin/magento cache:flush
Test the affected product and category URLs again.
7. Check Magento Indexer Status
You can inspect individual indexers with:
php bin/magento indexer:status
You may see statuses such as:
Ready
Reindex Required
Working
If indexes are invalid:
php bin/magento indexer:reindex
For a large store, avoid unnecessarily rebuilding indexes during peak traffic.
8. Flush Magento Cache
Stale cache data can sometimes make a recently changed URL appear unavailable.
Run:
php bin/magento cache:status
Then:
php bin/magento cache:flush
If necessary, clean cache:
php bin/magento cache:clean
The difference is important:
cache:cleanremoves cache entries associated with Magento’s cache types.cache:flushremoves cache storage contents.
Use cache commands deliberately, particularly on high-traffic production stores.
9. Check Magento Base URLs
Incorrect Base URL settings can result in broken links and unexpected 404 errors.
Check the configured URLs:
php bin/magento config:show web/unsecure/base_url
And:
php bin/magento config:show web/secure/base_url
For an HTTPS store, they should generally point to the correct domain.
For example:
https://example.com/
Also check the secure and unsecure Base URLs if your Magento version and configuration use both.
After correcting configuration, flush the cache:
php bin/magento cache:flush
10. Check Store View Configuration
Magento supports multiple websites, stores, and store views.
A URL may work in one store view but return 404 in another.
Check:
Stores → All Stores
Then verify:
- Website
- Store
- Store View
- Domain configuration
- Product assignment
- Category assignment
This is particularly important for multilingual Magento installations.
11. Check CMS Pages
If a CMS page such as:
/about-us
returns 404, go to:
Content → Pages
Find the page and verify:
- Enable status
- URL Key
- Store View
- Page content
- Design configuration
For example, a page may have the URL key:
about-us
but only be assigned to a different store view.
Save the page and clear the cache.
12. Check CMS URL Rewrites
A CMS page can also have an incorrect rewrite.
Go to:
Marketing → SEO & Search → URL Rewrites
Search for the CMS page’s request path.
Verify that the rewrite points to the correct CMS page.
If a conflicting rewrite exists, investigate it before deleting anything.
13. Check .htaccess on Apache
If Magento is running on Apache, .htaccess plays an important role in URL rewriting.
Magento’s root directory normally contains:
.htaccess
If this file has been modified, deleted, or corrupted, friendly URLs may stop working.
Check:
ls -la
Then:
ls -la .htaccess
If the file is missing, restore the correct version for your Magento installation rather than copying an unrelated .htaccess file from another project.
Also verify that Apache allows overrides for the Magento document root.
14. Check Nginx Configuration
Nginx does not use .htaccess.
Magento requires an appropriate Nginx configuration that handles requests correctly and points the site to the correct document root.
A typical Magento installation uses:
pub/
as the web-accessible document root.
If Nginx points to the Magento project root instead of pub, routing and security can be affected.
After making configuration changes, test the configuration:
nginx -t
Then reload Nginx:
systemctl reload nginx
Do not reload Nginx if the configuration test reports errors.
15. Verify the Magento Document Root
One of the most common causes of widespread Magento 404 errors is an incorrect document root.
For a Composer-based Magento installation, the web server should generally point to:
/path/to/magento/pub
rather than:
/path/to/magento
For example:
/home/user/magento/pub
If the server points to the wrong directory, Magento’s routing and static assets may not work correctly.
This is especially important after:
- Server migration
- cPanel to DirectAdmin migration
- Nginx migration
- Apache migration
- New virtual host creation
- Domain changes
16. Check Static Content 404 Errors
If your storefront loads but CSS and JavaScript files return 404 errors, the problem is likely related to static content.
You may see URLs similar to:
/pub/static/frontend/Vendor/theme/en_US/...
Check your deployment mode:
php bin/magento deploy:mode:show
Then regenerate static content:
php bin/magento setup:static-content:deploy -f
Flush the cache:
php bin/magento cache:flush
If necessary, clear generated static files before redeploying, but do so carefully on production systems.
17. Check Static File Permissions
Incorrect permissions can prevent Magento from serving generated assets correctly.
Check:
ls -ld pub pub/static pub/media
Also inspect specific files that return 404.
Do not solve permission problems by running:
chmod -R 777 .
This is insecure and can introduce additional problems.
Use the ownership and permission model appropriate for your Magento server.
18. Check Media Image 404 Errors
If product images return 404, verify that the files actually exist.
Magento media files are generally stored under:
pub/media/
For example:
ls -la pub/media/catalog/product/
If the image file is missing, Magento cannot serve it regardless of cache settings.
This can happen after:
- Incomplete migration
- Incorrect backup restoration
- Manual file deletion
- Failed media synchronization
- Incorrect deployment process
Make sure pub/media was included when moving Magento to a new server.
19. Check Case Sensitivity
Linux filesystems are normally case-sensitive.
For example:
Image.jpg
is different from:
image.jpg
A URL referencing the wrong filename can therefore return 404.
This issue can appear after moving a Magento store from a case-insensitive development environment to Linux production.
Check the actual filename:
find pub/media -iname "image.jpg"
Correct references where necessary.
20. Check the Admin URL
If the Magento Admin URL returns 404, first determine whether the Admin path is correct.
Run:
php bin/magento info:adminuri
Magento may return something similar to:
/admin_xxxxx
Use the exact configured Admin URI.
If you recently changed the Admin URL, flush the cache:
php bin/magento cache:flush
Also verify that your web-server configuration correctly handles the Magento Admin path.
21. Check app/etc/env.php
The Magento environment configuration is stored in:
app/etc/env.php
A broken configuration can cause routing and application problems.
Before modifying it, make a backup:
cp app/etc/env.php app/etc/env.php.backup
Validate its PHP syntax:
php -l app/etc/env.php
If the file contains syntax errors, correct them carefully.
Do not expose the contents of env.php publicly because it can contain sensitive credentials.
22. Check for Recently Installed Extensions
If the 404 errors appeared immediately after installing an extension, the extension may have introduced:
- Custom routes
- URL rewrites
- Controllers
- Plugins
- Observers
- Layout changes
- Custom frontend paths
Check enabled modules:
php bin/magento module:status
Review the extension’s documentation and Magento logs before disabling it.
If you are certain a recently installed module is responsible, disable it:
php bin/magento module:disable Vendor_Module
Then:
php bin/magento setup:upgrade
php bin/magento cache:flush
Avoid disabling core Magento modules without understanding their dependencies.
23. Check Custom Theme Changes
A custom theme can also introduce frontend routing or asset problems.
If the 404 affects only a specific page or frontend area after a theme update, inspect the latest theme changes.
Check:
- Layout XML
- Static assets
- Template references
- Custom JavaScript
- CSS files
- Theme registration
- Store-view assignment
If possible, test the issue with a known-good theme in a staging environment.
24. Check Web Server Rewrite Rules
Magento relies heavily on URL rewriting.
For Apache, verify that rewrite support is enabled.
A typical check is:
apachectl -M | grep rewrite
If the rewrite module is not loaded, Magento-friendly URLs may fail.
For Nginx, inspect the Magento-specific routing configuration instead.
Incorrect rewrite rules can cause:
- Product 404 errors
- Category 404 errors
- CMS 404 errors
- Admin routing problems
- Static file failures
25. Check the pub Directory
Magento’s public files should generally be served from:
pub/
Check:
ls -la pub
You should find directories such as:
media
static
errors
If the web server points somewhere else, many requests may fail.
This is one of the first things to verify after a server migration.
26. Check the var/report Directory
Depending on the Magento version and configuration, additional diagnostic information may be generated under:
var/report/
Check for recently created report files:
ls -lt var/report | head
If a 404 is accompanied by an application exception, the report may provide additional information.
27. Check Logs for Routing Errors
Search Magento logs for relevant errors:
grep -i "404" var/log/system.log
Also inspect exceptions:
grep -i "not found" var/log/exception.log
For web-server logs:
grep " 404 " /var/log/nginx/access.log
or the appropriate Apache access log.
This can help identify whether the 404 affects:
- One URL
- One product
- One category
- Static files
- Images
- The entire site
28. Fix 404 Errors After a Magento Migration
If the problem started after moving Magento to another server, check these items first:
- Verify the document root.
- Confirm the
pubdirectory is being served. - Verify Nginx or Apache configuration.
- Copy all Magento files.
- Copy
pub/media. - Restore the database.
- Check
app/etc/env.php. - Verify Base URLs.
- Check PHP compatibility.
- Run Magento upgrade commands if required.
- Deploy static content.
- Flush cache.
- Reindex.
- Verify DNS and SSL.
A migration can appear successful while missing static files, media, rewrite rules, or server configuration.
29. Fix 404 Errors After Changing the Domain
Changing the Magento domain can produce broken URLs if the old Base URL remains configured.
Check:
php bin/magento config:show web/unsecure/base_url
and:
php bin/magento config:show web/secure/base_url
Update them if necessary.
Then:
php bin/magento cache:flush
Also review:
- URL rewrites
- Store views
- Canonical URLs
- Sitemap
- Robots.txt
- CDN configuration
- SSL
- DNS
- Redirects
Do not perform a blind search-and-replace across the database because serialized Magento data and unrelated values can be damaged.
30. Check CDN and Reverse Proxy Caching
A CDN or reverse proxy may cache a 404 response.
If the Magento application is working correctly but customers continue receiving 404 responses, purge the relevant cache and test the origin server directly.
Check:
- CDN cache
- Reverse proxy cache
- Load balancer
- Origin server
- Cache-control headers
Do not assume Magento is responsible for every 404 seen by visitors.
31. Use a Controlled URL Rewrite
If an old URL needs to point to a new product or category, create a proper Magento URL rewrite rather than simply allowing the old address to return 404.
Go to:
Marketing → SEO & Search → URL Rewrites
Create a redirect where appropriate.
For a permanently moved page, a 301 redirect is generally the appropriate choice.
For example:
Old URL:
old-product.html
New URL:
new-product.html
Redirect:
301 Permanent
This helps preserve user access and can also reduce SEO problems caused by unnecessary broken links.
32. Avoid Creating Duplicate URL Rewrites
Before creating a new rewrite, search for the existing request path.
Duplicate or conflicting rewrites can create confusing routing behavior.
Always check:
Request Path
Target Path
Store View
Redirect Type
before creating or modifying a rewrite.
33. Check URL Suffix Configuration
Magento can use URL suffixes such as:
.html
If URL suffix settings were changed, existing links may no longer match the current configuration.
Review the relevant catalog URL settings in:
Stores → Configuration → Catalog
and check:
- Product URL Suffix
- Category URL Suffix
Do not change URL suffix settings on a live store without planning redirects for existing URLs.
34. Check the url_rewrite Database Table Carefully
Magento stores URL rewrite information in the database.
The relevant table is commonly:
url_rewrite
Advanced administrators can inspect it using SQL.
For example:
SELECT request_path, target_path, redirect_type, store_id
FROM url_rewrite
WHERE request_path = 'example-product.html';
Do not directly modify or delete production URL rewrite records unless you fully understand the consequences.
Use Magento’s Admin Panel or supported Magento mechanisms whenever possible.
Always back up the database before making direct database changes.
35. Fix a 404 After Changing Product URLs
If a product previously used:
old-product.html
and now uses:
new-product.html
the old address may return 404.
For an established product, consider creating a 301 redirect:
old-product.html → new-product.html
This provides a better experience for users who still have the old URL bookmarked or indexed by search engines.
36. Fix 404 Errors for JavaScript and CSS
If browser developer tools show errors such as:
GET /static/... 404
check:
php bin/magento deploy:mode:show
Then regenerate static files:
php bin/magento setup:static-content:deploy -f
Clear Magento cache:
php bin/magento cache:flush
Also inspect:
pub/static/
and verify that the web server can access it.
37. Fix 404 Errors for Product Images
If images are missing:
- Verify the files exist in
pub/media. - Check file ownership.
- Check media permissions.
- Verify the media URL.
- Clear cache.
- Check CDN configuration.
- Confirm the migration included media files.
Do not regenerate or replace thousands of images before determining whether the files are actually missing.
38. Test the Store After Making Changes
After fixing the problem, test more than the URL that originally failed.
Check:
Frontend
- Homepage
- Product page
- Category page
- Search
- CMS pages
- Images
- CSS
- JavaScript
- Cart
- Checkout
Admin
- Login
- Dashboard
- Products
- Categories
- Orders
- Configuration
Technical
- HTTP status codes
- Magento logs
- Web-server logs
- PHP-FPM logs
- Cache
- Indexers
- Cron
Magento 404 Troubleshooting Checklist
Use this checklist when diagnosing a Magento 404:
- Confirm which URL returns 404
- Determine whether Magento or the web server generates it
- Verify the product/category exists
- Check product visibility
- Check the URL key
- Check URL rewrites
- Check indexer status
- Reindex if required
- Flush Magento cache
- Verify Base URLs
- Check store-view assignment
- Check CMS page configuration
- Verify
.htaccesson Apache - Verify Nginx configuration
- Verify the document root points to
pub - Check static content
- Check
pub/media - Check file permissions
- Check Magento logs
- Check web-server logs
- Review recent extensions
- Review theme changes
- Check Admin URI
- Check CDN or reverse proxy
- Check domain configuration
- Test redirects
- Test the complete storefront
How to Prevent Magento 404 Errors
Preventing broken URLs is easier than repairing hundreds of them later.
Keep URL Changes Controlled
Avoid changing product and category URL keys unnecessarily.
Use 301 Redirects
When an established URL changes, redirect the old URL to the new one.
Monitor Search Console
Regularly monitor crawl errors and indexed URLs to identify broken links.
Test Deployments
Test URL routing, static assets, and media files after deployments.
Maintain Backups
Keep reliable backups of both Magento files and the database.
Test Migrations
Before switching DNS after a migration, test the new server using a temporary hostname or local hosts-file configuration.
Monitor 404 Rates
A sudden increase in 404 responses can indicate:
- Broken deployment
- Incorrect rewrite rules
- Missing static files
- Incorrect domain configuration
- Deleted products
- Bad extension updates
Monitoring 404 rates can help detect these problems quickly.
Final Thoughts
Magento 404 errors can have many causes, ranging from a deleted product to an incorrectly configured web server. The most effective troubleshooting approach is to first identify which URLs are failing and whether the response is generated by Magento, the web server, or an intermediate CDN.
For product and category pages, investigate URL keys, URL rewrites, store views, and indexers. For CSS and JavaScript, focus on static content deployment and the pub/static directory. For images, inspect pub/media. If the entire store returns 404, check the web-server configuration and make sure the document root points to Magento’s pub directory.
Avoid making multiple changes simultaneously. Back up the store before modifying configuration or database records, make one controlled change at a time, and verify the result.
With proper URL management, controlled deployments, redirects, monitoring, and regular backups, Magento 404 errors can be significantly reduced and much easier to resolve when they occur.