Magento 2.4.2 .htaccess changes...

I have just noticed, In Magento 2.4.2 release, the Magento root folder .htaccess file changed completely compared to the 2.4.1 release. I found this commit without much explanation, due to this change if the URI does not starts with pub, setup, update, dev, it will rewrite to the magento-root/pub/*. Previously magento recommends to set pub/ as doc root for the security reason. I hope this is the reason they modified .htaccess.

In the below examples, we set magento-root/ as doc root in the apache (not magento-root/pub/)

Example 1:

http://magento.default.m242/static/version1613058997/frontend/Magento/luma/en_US/mage/calendar.css (This will work because this URI does not start with pub so rewrite to pub/)


http://magento.default.m242/pub/static/version1613058997/frontend/Magento/luma/en_US/mage/calendar.css (This will also work because this URI already starts with pub so it will work as usual)


Example 2:

If we create a test.html file inside magento-root/, it will show 404 when we access http://magento.default.m242/test.html, because it does not start with pub so it will rewrite to pub/, in pub/ we don't have test.html so it will show 404 not found page.


If we create a test.html file inside magento-root/pub, it will show the page correctly when we access http://magento.default.m242/test.html, because it does not start with pub so it will rewrite to pub/, in pub/ we have test.html so it will show page correctly.

31 views0 comments

Recent Posts

See All