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
public function aroundProcess( \Magento\Framework\App\PageCache\Kernel $subject, callable $proceed, \Magento\Framework\App\Response\Http $response ) { if ($this->request->isHead() && $response->getHttpResponseCode() == 404) { return; } return $proceed($response); }
Installation
Install via composer (recommend)
Run the following command in Magento 2 root folder:
composer require elpas0/magento2-fix-homepage-404 php bin/magento setup:upgrade php bin/magento setup:static-content:deploy php bin/magento cache:clean
Check this article for details – install magento 2 module using github
Install ready-to-paste package
- Download package from magento2-fix-homepage-404.zip
- Unzip it
- Upload it to your magento root (
package/app >> [magento]/app
) - Run the following command in Magento 2 root folder:
php bin/magento setup:upgrade
– Upgrades the Magento application, DB data, and schema
php bin/magento setup:static-content:deploy
– Deploys static view files
php bin/magento cache:clean
– Cleans cache type(s)
Uninstallation
Magento 2: How to disable module
Magento 2: How to uninstall module
Thanks for posting it.
I was facing same issue on one of my live website.
Using your code it was fixed.
It helped me a lot.
thanks again!!
That’s one informative article. Thank’s for the share.
Thanks mate, for the article. it help me a bit in reconfiguring the homepage.
Glad it is useful!
That’s one informative article. Thank’s for the share.