0

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?

Sanaullah Ahmad
  • 587
  • 1
  • 5
  • 23

2 Answers2

1

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!

Diana
  • 5,137
  • 1
  • 11
  • 26
  • 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 http://127.0.0.1 only. – Sanaullah Ahmad Apr 07 '21 at 10:29
1

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/'
            ]
        ]
    ]
],
Baharuni Asif
  • 1,217
  • 9
  • 26