Magento Tips & Tricks

Magento 2: Homepage 404 error

Your magento store index page shows 404 page? Magento 2 homepage 404 error is a common issue. There are several reasons that could cause it. Lets check possible scenarios from easy to difficult.

Store Configuration Issue

Your store configuration point to wrong CMS page. CMS Home page was deleted or recreated, or you were experimenting with single store / multistore. What you need to do is :

  • Login to admin
  • Navigate to Stores > Configuration.
  • Select General > Web tab in left column and open Default Pages section
  • Set correct value for CMS Home Page option
  • Option value can be overrided on different scope level. Scope switch located in top left corner. It is recommended to check option value from the Store View scope.
  • flush the cache in System > Cache Management or via console command

Issues with URL Rewrite

Under certain circumstances product or category can have empty request_path value. To fix it:

  • login to your store database with any database manager ( like phpMyAdmin or HeidySQL )
  • check if you have any records with empty request path by running following SQL
    SELECT * FROM url_rewrite WHERE request_path='';
  • delete those entries. It can be done manually or with SQL
    DELETE FROM url_rewrite WHERE request_path='';
  • flush the cache in System > Cache Management or via console command

Full page Cache issue

Full page cache can’t distinguish GET request from HEAD request. If you do not have cached data or it is invalidated and web crawler send HEAD type request to your site, magento return 404 page and cache it. After that any GET request with see 404 page until you flush FPC. Magento team stated that bug is fixed in Magento 2.3.2

To fix it we create a plugin to wrap process function from Magento\Framework\App\PageCache\Kernel

Complete module code can be found on github.
Ready-to-paste package – magento2-fix-homepage-404.zip

Installation

Install via composer (recommend)

Run the following command in Magento 2 root folder:

Check this article for details – install magento 2 module using github

Install ready-to-paste package

Uninstallation

Magento 2: How to disable module
Magento 2: How to uninstall module

Leave a Reply

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