DEBUG - letronghieu4897/magento GitHub Wiki
DEBUG
Go Footer
1. Collection dump sql select
2. Collection filter value on column
3. Add extension Netpower Base to show block/container on inspect
4. getData from Repository class
5. Magento 2.3 Page 404 errors with FPC enabled
1.Collection dump sql select
Go Header
1. Use for CollectionFactory value.
EXAMPLE : collectionFactory $collection;
2. var_dump($collection->getSelect()->__toString()); // dump sql select collection on database.
3. Copy sql dumped above to run query.
2.Collection filter value on column
Go Header
1. Filter value of collection.
2. $collection->addFieldToFilter('column','value');
3.Add extension Netpower Base
Go Header
1. copy folder Netpower/Base into app/code/
2. php bin/magento setup:upgrade
4.getData from Repository class
Go Header
$products = \Magento\Framework\App\ObjectManager::getInstance();
$attribute = $products->get('\Magento\Catalog\Model\Product\Attribute\Repository')->get($attributeCodeItem)->getData();
var_dump($attribute);
5.Magento 2.3 Page 404 errors with FPC enabled
Go Header
APACHE
Try updating the .htaccess file to add the HTTP HEAD block below the already existing TRACE and TRACK block. Then flush the cache and 404 should not return.
############################################
## TRACE and TRACK HTTP methods disabled to prevent XSS attacks
RewriteCond %{REQUEST_METHOD} ^TRAC[EK]
RewriteRule .* - [L,R=405]
############################################
## HEAD HTTP methods disabled due to https://github.com/magento/magento2/issues/20255
RewriteCond %{REQUEST_METHOD} HEAD
RewriteRule .* - [L,R=405]
DETAIL
This got me thinking the HTTP HEAD request was causing the 404 to get stuck in the FPC for the requested URI. To prove this open a page on a Magento 2.3.0 or 2.3.1 site, open browser developer tools, and make a HEAD request by pasting the following into the Javascript Console:
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("HEAD", "/customer/account/create/", true);
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState==4) {
console.log(xmlhttp.getAllResponseHeaders());
}
}
xmlhttp.send(null);
Which returns: HEAD https://{site.testing.domain}/customer/account/create/ 404 (Not Found)
Now the customer account creation page return 404 and the FPC cache needs to be flushed to clear.
Based on the above finds I took the quick route of blocking all HEAD request using the existing .htaccess. Obviously, NGINX would require config addition. I've read about the potential traffic drawbacks of rejecting all HEAD request so I imagine a more graceful/targeted workaround could be developed.
Credit for detailing how to make HEAD requests in a browser: LINK
NGINX
I added the following NGINX configuration to the SSL termination server{} block (pre-Varnish) and confirmed it returns 405 for HEAD requests. I imagine it would work added in your version of nginx.conf.sample (post-Varnish) if needed
## HEAD HTTP methods disabled due to https://github.com/magento/magento2/issues/20255
if ( $request_method = HEAD ) {
return 405;
}
Edit: added index.php details for NGINX not behind Varnish and unable to update the server configuration
If all else fails you can try blocking 405 in index.php prior to Magento bootstrap. Find the Bootstrap::create line in index.php and add the following above it:
// HEAD HTTP methods disabled due to https://github.com/magento/magento2/issues/20255
if (false !== stripos($_SERVER['REQUEST_METHOD'], 'HEAD')) {
header("HTTP/1.1 405 Method Not Allowed");
http_response_code(405);
exit();
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);