I have a magento2.4 store running on server. I installed it on localhost but it give 404 error. enter image description here

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. enter image description here

Can you suggest some solution to this problem?

2 Answers 2


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:

  1. 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
  2. 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!

  • 1
    in /etc/apache2/sites-available/000-default.conf, i changed DocumentRoot /var/www/html/m2-dogdream/pub and restarted apache, than site was accessed by only. Commented Apr 7, 2021 at 10:29

After Installed magento 2.4 version your localhost support with /pub directory like {localhostname}/pub/index.php

We can access without pub directory follow below steps

1. Copy .httaccess file from pub folder and override it to root .htaccess file

2. Upload pub/index.php file to root magento directory

3. Add below code in app/etc/env.php file

'system' => [
    'default' => [
        'web' => [
            'unsecure' => [
                'base_media_url' => '{{secure_base_url}}pub/media/',
                'base_static_url' => '{{secure_base_url}}pub/static/'
            'secure' => [
                'base_media_url' => '{{secure_base_url}}pub/media/',
                'base_static_url' => '{{secure_base_url}}pub/static/'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.