Magento2 store not running on localhost .htaccess file problem
-
16-04-2021 - |
题
I have a magento2.4 store running on server. I installed it on localhost but it give 404 error.
It has a strange .htaccess file contents.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/pub/
RewriteCond %{REQUEST_URI} !^/setup/
RewriteCond %{REQUEST_URI} !^/update/
RewriteCond %{REQUEST_URI} !^/dev/
RewriteRule .* /pub/$0 [L]
DirectoryIndex index.php
If i change the .htaccess file content to a standard M2 .htaccess than it gives directory content.
Can you suggest some solution to this problem?
解决方案
This problem you are facing is due to the new rules of M2.4.2 which will now serve all requests from the <magento_root>/pub
folder. This is kind of incompatible with what you are trying to do - launching Magento from a folder directly in browser without a dedicated virtual host.
You have 2 options:
- Create a dedicated virtual host and set the
DocumentRoot
to point to the<magento_root>/pub
folder - for this approach check my answer in this thread The requested URL /pub/ was not found on this server. - Magento .htaccess problem - Try to make Magento accept that you are not having a dedicated virtual host and adapt the Apache instructions - and for this approach I suggest you read the answers given by me and @iphigenie in the thread frontend and admin not working magento 2.4.2 upgrade
Good Luck!