I recently upgraded one Magento installation on my local from 2.3.6-p1 to 2.4.2, and then I started getting 404 error for all pages on front end and backend, below are the technical details of server, and few tries I already made:

values set in httpd.conf (as I run multiple websites so I place them in subdirectory of /var/www/html)

Timeout 600
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
    AllowOverride none
    Require all denied
DocumentRoot "/var/www/html"
<Directory "/var/www">
    AllowOverride All
    Order allow,deny
    Allow from all
    # Allow open access:
    Require all granted
# Further relax access to the default document root:
<Directory "/var/www/html">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all      
    Require all granted

root .htacces file:

<IfModule mod_rewrite.c>
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

Note: I added ifmodule statement here to confirm that mod rewrite is installed and working.

I have cleared all cache and generated folders using the command below:

rm -rf pub/static/frontend/* pub/static/adminhtml/* var/cache/ var/generation/ var/page_cache/ var/view_preprocessed/ var/composer_home generated/

and then recompiled and deployed, but not working for me, can anyone help me for the same.


2 Answers 2


Change DocumentRoot "/var/www/html" to DocumentRoot "/var/www/html/pub" and reload apache.

Please read more details in this thread frontend and admin not working magento 2.4.2 upgrade where I explained why this is needed.

Also, there is an answer there from @iphigenie https://magento.stackexchange.com/a/332405/35330 that attempts to solve the problem of using subfolders for running Magento.

  • I am running multiple website under /var/ww/html using sub directories like mydir1, mydir2 and even if I change document root to pub, the path /var/www/html/pub doesn't exist, as the pub folder is inside my subdirectory and its present in each magento installation I have. Commented Mar 30, 2021 at 6:47
  • I updated my answer, check it out, maybe it helps
    – Diana
    Commented Mar 30, 2021 at 6:53
  • 1
    Sorrry for very much delayed response, but finally configured Apache httpd.conf to have pub as root directory for my virtual host entry for the particular website. Commented May 26, 2021 at 8:26

It seems now Magento will only load from pub folder. By default it will not be possible to load it from the root of Magento.

So the best solution for this is to create a virtual host and point it to pub directory.


Meanwhile, as an alternative to run this on local machine I tried something else that seems to be working fine with the default setup. Like earlier we were using the base_url as So instead of this now we need to use as the base_url. Secure and Unsecure URL needs to be setup on the basis of this.

Setting this up will avoid the issue of 404 page coming.

Note: Verified this with the default Magento only. Not sure for the projects having much complex functionalities. But you can give this a try.

We have another option without adding /pub 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.