cancel
Showing results for 
Search instead for 
Did you mean: 

.htaccess file for Magento 2.4

.htaccess file for Magento 2.4

Hello,

I have installed Magento 2.4 on Apache 2 sever running on Ubuntu 20.x

When I try to load the magento root directory on browser, I get

 

 

Not Found
The requested URL was not found on this server.

 

 

I have the .htaccess (default file created by install) like this

 

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

 

 

Can someone help me understand what this is trying to do?

 

My understanding is, this is looking for index.php file (which is not present in the root installation directory - and thus the error).

 

I have a feeling that the error has to do something with the line

 

RewriteRule .* /pub/$0 [L]

 

 

Thanks in advance!

3 REPLIES 3

Re: .htaccess file for Magento 2.4

The default, root .htacess is the same as yours.

 

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

I've noticed as of version 2.4.2 there is another .htaccess file in /pub which is the .htaccess file that was originally root. Please check /pub/.htaccess too. The corresponding index.php is stored in /pub too.

If it's a fresh install of Magento then generally it's a server side issue. Check for missing php packages, check error log.

Re: .htaccess file for Magento 2.4

Thank you so much! I was stuck on this for so long and you fixed it.

Re: .htaccess file for Magento 2.4

So, how did he help you with this? I have exactly the same setup and error. There is the standard .htaccess in place in both folders (for me it is .../shop and .../shop/pub). From the rror log I can see, that the "shop" part in the URL is missing. 

 

I installed in .../html/shop and set the base-URL to /shop accordingly. In the error logs I saw that it looks for server-address/pub instead of server-address/shop/pub. From phpinfo() I know that rewrite is available. When I modifiy the htaccess like this:

RewriteRule .* /shop/pub/$0 [L]

the shop loads but I cannot access the admin link and it just loads the frame but gives me an error loading any concrete pages.