9

Magento 2.3 homepage returns a 404 Page Not Found error. This only occurs when not logged in. After logging in, the homepage works properly. (It seems to work in mobile view even when returning a 404 at the desktop view.)

Also after cache:clean page_cache, homepage working properly.

Does anyone has faced this type of issue?

6
  • Have you found a cause for this issue? I'm also facing it. It happens randomly, without having any empty records in url_rewrites, and goes back to normal after clearing the cache. Thanks! Commented Mar 11, 2019 at 4:57
  • No, we tried to trace it. Do you face from how many time? Commented Mar 11, 2019 at 5:03
  • You do not need to clear all cache. We traced that after clear only full page cache, It's also working. php bin/magento cache:clean full_page Commented Mar 11, 2019 at 5:06
  • It happens completely random, without anything logged. I opened an issue on github, maybe you can post your input there as well: github.com/magento/magento2/issues/21703 Commented Mar 12, 2019 at 5:11
  • We have same issue on magento 2.3.1 with homepage on clean install with Luma Sample data. Commented Jun 17, 2019 at 12:19

7 Answers 7

8

Enter in you database and run this :

SELECT * FROM `url_rewrite` WHERE request_path='';

Delete the rows and after that do :

php bin/magento setup:upgrade
php bin/magento cache:flush
  • Disable the Page Cache , and see if the error persist .

  • Check if you have redis cache , and clean it .

  • See the template assigned in homepage , check the console for any errors.
7
4

Same issue in my new Magento 2.3.1 site, my site doesn't have blank request_path.

The reason is built in page cache doesn't distinguish the GET and HEAD requests and not cache them separately. After HEAD requests with response 404, the home page gets cached, and after that any valid GET request returns 404 until FPC is refreshed.

The official said the bug is fixed in Magento 2.3.2 https://github.com/magento/magento2/issues/21299#issuecomment-485144642

1
  • 2
    This should be the accepted answer given the question is about 2.3 specifically. (The other answers about URL rewrites can cause the same symptom, but that's been true for all versions and isn't helped by clearing cache.) Commented Jul 31, 2019 at 21:57
3

We also have this problem on 3 separate installations of Magento 2.3, all on different servers.

This has only happened since the upgrade from 2.2.6 and seems to occur at exactly the same point in time every day (no errors in any logs).

Clearing the cache fixes the issue, but not the problem.

2
  • Have you found what was the exact issue? Commented Mar 4, 2019 at 6:51
  • No, not yet, we just added a scheduled task which checks for a 404 every minute and refreshes the cache if found. Not ideal, but the best fix we could find. Only happened since the upgrade to Magento 2.3 though.
    – Dan
    Commented Mar 12, 2019 at 8:51
3

check url_rewrite table , into that table home page blank request_path entry there and removed that entry, then check

php bin/magento cache:flush
php bin/magento cache:clean
1
3

We are facing the same issue as well and it still needs to be debugged in detail. But we are using below as the temporary fix

Modify 'aroundDispatch' method of file vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php like below

public function aroundDispatch(
        \Magento\Framework\App\FrontControllerInterface $subject,
        \Closure $proceed,
        \Magento\Framework\App\RequestInterface $request
    ) {
        $this->version->process();
        if (!$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN) {
            return $proceed($request);
        }
        $result = $this->kernel->load();
        if ($result === false || ($result instanceof ResponseHttp && $result->getStatusCode() == 404)) {
            $result = $proceed($request);
            if ($result instanceof ResponseHttp) {
                $this->addDebugHeaders($result);
                $this->kernel->process($result);
            }
        } else {
            $this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'HIT', true);
        }
        return $result;
    }

The change in function is: IF condition changed from

if ($result === false) {

to

if ($result === false || ($result instanceof ResponseHttp && $result->getStatusCode() == 404)) {

This code change will ignore and re-build full page cache if the result found in the cache is 404.

I hope this helps.

1

Looks like this is caused by Magento 2 full page cache bug in muti-store views. I have disabled the full page cache from env.php. It seems to fixes the issue. Have to debug more to find out.

Will update you guys soon.

Updates. found the issue. This is because Magento 2 is not handling HTTP HEAD requests. When a bot hits the website with HEAD type request, Magento returns 404 and caches it. The solution as below:

From e3890bfda2d67508df76ce00cdd675c60743ace5 Mon Sep 17 00:00:00 2001
From: Siyu Qian <[email protected]>
Date: Fri, 7 Jun 2019 15:17:40 +1200
Subject: [PATCH] BMQ-54 Full page cache issue

---
 .../Plugin/PreventCachingHead404ResultsPlugin.php  | 37 ++++++++++++++++++++++
 app/code/MageBinary/Theme/etc/di.xml               |  3 ++
 2 files changed, 40 insertions(+)
 create mode 100644 app/code/MageBinary/Theme/Plugin/PreventCachingHead404ResultsPlugin.php

diff --git a/app/code/MageBinary/Theme/Plugin/PreventCachingHead404ResultsPlugin.php b/app/code/MageBinary/Theme/Plugin/PreventCachingHead404ResultsPlugin.php
new file mode 100644
index 0000000..a16ad17
--- /dev/null
+++ b/app/code/MageBinary/Theme/Plugin/PreventCachingHead404ResultsPlugin.php
@@ -0,0 +1,37 @@
+<?php
+namespace MageBinary\Theme\Plugin;
+
+class PreventCachingHead404ResultsPlugin
+{
+    /**
+     * @var \Magento\Framework\App\Request\Http
+     */
+    protected $request;
+
+    /**
+     * PreventCachingHeadRequestsPlugin constructor.
+     * @param \Magento\Framework\App\Request\Http $request
+     */
+    public function __construct(\Magento\Framework\App\Request\Http $request)
+    {
+        $this->request = $request;
+    }
+
+    /**
+     * Prevent caching HEAD requests that return a 404 result
+     * @param \Magento\Framework\App\PageCache\Kernel $subject
+     * @param callable $proceed
+     * @param \Magento\Framework\App\Response\Http $response
+     * @return void
+     */
+    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);
+    }
+}
\ No newline at end of file
diff --git a/app/code/MageBinary/Theme/etc/di.xml b/app/code/MageBinary/Theme/etc/di.xml
index 5dfebc7..7df8e7a 100644
--- a/app/code/MageBinary/Theme/etc/di.xml
+++ b/app/code/MageBinary/Theme/etc/di.xml
@@ -16,4 +16,7 @@
     </type>
     <preference for="Magento\Framework\Url\QueryParamsResolver" type="MageBinary\Theme\Url\QueryParamsResolver" />
     <preference for="Magento\CatalogWidget\Model\Rule\Condition\Product" type="MageBinary\Theme\CatalogWidget\Rule\Condition\Product" />
+    <type name="Magento\Framework\App\PageCache\Kernel">
+        <plugin name="prevent_caching_404_head_results" type="MageBinary\Theme\Plugin\PreventCachingHead404ResultsPlugin" />
+    </type>
 </config>
-- 
2.10.5
1
  • did you found any solution for full page cache 404 issue on home page ? I have facing same issues on home page where somtimes homepage will be 404 and if i clean full page cache, it's working fine.
    – Ajay
    Commented May 24, 2019 at 5:06
0

We are facing the same issue. Home page and some other pages randomly give 404. After clearing the page cache, it works fine. It happens rather randomly - sometimes happens straight for 4 minutes. Then it doesn't happen for the next 5 hours etc. No empty request_paths in the url_rewrite table. In our case the issue appeared after we:

  • Updated Magento 2.3.0 -> 2.3.1
  • Disabled Redis

Will investigate further.

3
  • Do you have any news? I am working on magento 2.3.1 and facing the same problem.
    – Plim
    Commented May 8, 2020 at 14:03
  • 1
    @Plim Yes. It was fixed in 2.3.2. You can either update or patch. github.com/magento/magento2/issues/21299 In short: HEAD request gives 404 and on different pages and then those pages get cached. And until you clear the cache, it keeps showing 404.
    – Raido
    Commented May 25, 2020 at 10:54
  • Thanki you @Raido, worked for me.
    – Plim
    Commented May 30, 2020 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.