magento2: HEAD request returns 404
Preconditions (*)
- Magento 2.3.0
- HTTPS
- Nginx
Steps to reproduce (*)
- Clear FPC and don’t access the site
- Run
curl -X HEAD -i https://demo1-m2.mage.direct/orcurl -I https://demo1-m2.mage.direct/ - After couple of HEAD requests with response 404 the home page gets cached and after that any valid GET request returns 404 until FPC is refreshed.
Expected result (*)
- I expect HEAD request to return 200 and not 404
Actual result (*)
- HEAD request returns 404
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 9
- Comments: 36 (31 by maintainers)
Commits related to this issue
- Fix for bug HEAD request returns 404 #21299 - CMS index action is not handling head requests — committed to Jitheesh/magento2 by Jitheesh 5 years ago
- Fix for issue #21299. Changed the built-in cache to not cache 404 responses to HEAD requests. — committed to mattijv/magento2 by mattijv 5 years ago
- Fix for issue #21299. HEAD requests map to GET request interface and are sent without body attached. — committed to mattijv/magento2 by mattijv 5 years ago
- Revert "Fix for issue #21299. Changed the built-in cache to not cache 404 responses to HEAD requests." This reverts commit 46191d82d04e2392cb58a2c03121987a14052043. — committed to mattijv/magento2 by mattijv 5 years ago
- Fix for issue #21299. Change HEAD action mapping to GET action interface and add HEAD request handling — committed to mattijv/magento2 by deleted user 5 years ago
- Fix for issue #21299. Change HEAD action mapping to GET action interface and add HEAD request handling — committed to mattijv/magento2 by deleted user 5 years ago
- Fix for issue #21299. Change HEAD action mapping to GET action interface and add HEAD request handling — committed to mattijv/magento2 by deleted user 5 years ago
- ENGCOM-4474: Fix for issue #21299. Change HEAD action mapping to GET action interface and add HEAD request handling #21378 - Merge Pull Request magento/magento2#21378 from mattijv/magento2:2.3-devel... — committed to magento/magento2 by magento-engcom-team 5 years ago
- ENGCOM-4474: Fix for issue #21299. Change HEAD action mapping to GET action interface and add HEAD request handling #21378 — committed to magento/magento2 by sidolov 5 years ago
Hi @kolucciy. Thank you for your report. The issue has been fixed in magento/magento2#21378 by @mattijv in 2.3-develop branch Related commit(s):
The fix will be available with the upcoming 2.3.2 release.
This is an issue with the Magento built-in full page cache. Here’s a quick fix for the issue while waiting for Magento to fix the root cause in the core:
Add this plugin in a di.xml somewhere
And create the following class in the path defined by the di.xml file
Alternatively you can disable the fullpage cache, but that is not advisable since it affects performance. Better solution is to put the store behind a Varnish cache, since that seems to be unaffected by this.
Got it. I only patched
app/etc/di.xml, but now I understood that I (also?) have to patch the filevendor/magento/magento2-base/app/etc/di.xml. Thanks @mattijv!@SteveEdson While waiting for the next release you can do a couple interim fixes:
and/or
Have a production mode 2.3 site with Nginx that sometimes serves homepage as a 404 think this might be why. Suspect head requests sent by a “down notifier” service and then the 404 is cached and served up by full page cache.
Confirm 404 when doing Head request, flushing FPC cleans it out.
jQuery.ajax({ type: "HEAD", async: true, url: '/', }).done(function(message,text,jqXHR){ console.log(message, text, jqXHR.status) });Someone made a plugin module to work around this in the meantime, same as mattijv’s earlier post. https://github.com/magic42/module-prevent-head-404-cache
HEAD requests should be supported automatically (on the framework level) for all GET requests, just w/o body. Caching should take this into account (GET should have separate cache to avoid empty body).
Looks like also supported by @Vinai