2

Frontend and admin doesn't work or show only 404 not found pages

It is installed in a sub directory of root folder

The development in command line everything works

I can change the .htaccess file , it shows a little better but doesn't work

Cannot find any help yet, because not many have this issue or installed 2.4.2 yet

Guess that it has to do something with being a subfolder and new htaccess

Anyone has an effective solution?

Having front on takoda.shop and backup at takoda.shop/backup so working on 2 sites at the same time

3

I am really amazed that Magento pushed this to release without documenting it in the release note or "backwards incompatible" changes, but they did. They mention it in the installation notes, as pointed out in Diana's answer, but nowhere else.

There are several bugs filed on github where people share workarounds they are trying. Main one: https://jokiruiz.com/magento-2/how-to-run-magento-2-from-a-subdirectory/

and obviously the other options is making the change prior to upgrade https://devdocs.magento.com/guides/v2.4/install-gde/tutorials/change-docroot-to-pub.html

attempt #1 subfolder (not visible in url)

For testing purposes I have a test site upgraded to 2.4.2 and managed to find a config that uses a subfolder BUT the subfolder is invisible in the url.

  • magento installed in magento2-path subfolder
  • site working on www.mywebsite.com
  • if magento2-path was visible in url, and therefore set up in the site url-path config or in stylesheets, that must be cleaned out
  • www.mywebsite.com/magento2-path will 404

Note 2: to save work this does not have a local copy of the images and uses "static domain" for images so not certain it 100% correct for static files and probably some extra rule needed for pub/static

site-root
.htaccess
     magento2-path
     .htaccess
          pub
          .htaccess

the htaccess at the top has

RewriteEngine on

RewriteCond %{REQUEST_URI} !^/pub/
RewriteCond %{REQUEST_URI} !^/setup/
RewriteCond %{REQUEST_URI} !^/update/
RewriteCond %{REQUEST_URI} !^/dev/
RewriteCond %{REQUEST_URI} !^/magento2-path/setup/
RewriteCond %{REQUEST_URI} !^/magento2-path/update/
RewriteCond %{REQUEST_URI} !^/magento2-path/dev/
RewriteCond %{REQUEST_URI} !^/magento2-path/pub/
RewriteCond %{REQUEST_URI} !^/magento2-path/
RewriteRule .* /magento2-path/pub/$0 [L]

RewriteCond %{REQUEST_URI} ^/pub/
RewriteRule .* /magento2-path/$0 [L]

DirectoryIndex index.php

the htaccess in magento2-path is modified to (the / in front of pub is removed)

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

the htaccess in pub is not modified, except to add any special old "migration" rules I had from migration from past modules or pages that are now gone

attempt #2 subfolder (with redirect)

UPDATE: I have found that for a site that used the magento install path in the URL I can make it redirect so the page shows (without that path) only when the folder is renamed to not match the path anymore. Otherwise requests get passed down the stack. You want to make sure your "root level" rewrites are used, not the magento one.

  • magento was installed in magento2-path subfolder RENAME THIS FOLDER eg tomagento2-folder

  • site working on www.mywebsite.com

  • if magento2-path was visible in url, and therefore set up in the site url-path config or in stylesheets, that must be cleaned out

  • www.mywebsite.com/magento2-path/whatever redirects to www.mywebsite.com/whatever which displays correctly

    site-root .htaccess magento2-folder2 .htaccess pub .htaccess

the htaccess at the top has (note: this is total overkill i'm sure only half the redirects are needed but not got time to clean)

RewriteEngine on

RewriteRule ^/magento2-path/$ / [R=301,L]
RewriteRule ^/magento2-path$ / [R=301,L]
RewriteRule ^magento2-path/$ / [R=301,L]
RewriteRule ^magento2-path$ / [R=301,L]

RewriteCond %{REQUEST_URI} /magento2-path/
RewriteCond %{REQUEST_URI} !^/magento2-path/setup/
RewriteCond %{REQUEST_URI} !^/magento2-path/update/
RewriteCond %{REQUEST_URI} !^/magento2-path/dev/
RewriteCond %{REQUEST_URI} !^/magento2-path/pub/
RewriteRule ^magento2-path(.*) $1  [R=301,L]

RewriteCond %{REQUEST_URI} /alpineshop/
RewriteCond %{REQUEST_URI} !^/magento2-path/setup/
RewriteCond %{REQUEST_URI} !^/magento2-path/update/
RewriteCond %{REQUEST_URI} !^/magento2-path/dev/
RewriteCond %{REQUEST_URI} !^/magento2-path/pub/
RewriteRule ^/magento2-path/(.*) /$1  [R=301,L]


RewriteCond %{REQUEST_URI} !^/pub/
RewriteCond %{REQUEST_URI} !^/setup/
RewriteCond %{REQUEST_URI} !^/update/
RewriteCond %{REQUEST_URI} !^/dev/
RewriteCond %{REQUEST_URI} !^/magento2-path/setup/
RewriteCond %{REQUEST_URI} !^/magento2-path/update/
RewriteCond %{REQUEST_URI} !^/magento2-path/dev/
RewriteCond %{REQUEST_URI} !^/magento2-path/
RewriteRule .* /magento2-folder/pub/$0 [L]

RewriteCond %{REQUEST_URI} ^/pub/
RewriteRule .* /magento2-path/$0 [L]

DirectoryIndex index.php

the htaccess in magento2-folder and magento2-folder/pub is the same as above

8
  • Thanks, yes I saw your comment also, the thing is I work on the backup subdirectory to make updates, when finished I copy it to the root directory, for the visitors at the website, and keep working on the backup again, but now with this magento upgrade, it is hardly to do anymore, not yet really convenient with the virtual host parts, should have to keep digging into it, until solved :) – Alain Stout Mar 9 at 14:58
  • should be ok to copy app/code app/theme and vendor/ files without issues. Moving config changes is technically also possible but you'd have to spend a bit of time moving any "different" configurations into the "env.php" file (the one that is meant to be installation specific) – iphigenie Mar 9 at 15:09
  • So far it always worked this way, and had to change core_config urls next to env.php indeed, but now have to come up with new ways, what you mean with reverting htaccess? The only thing so far where I see something is changing htaccess in the backup root to: RewriteRule .* pub/$0 [L] I can see a little bit of frontend but admin also shows frontend XD – Alain Stout Mar 9 at 15:13
  • @alain-stout updated my answer with the config i currently have on a test site - alas it only allows to have a magento install on a "custom subdirectory" working without having to change the server root etc. back BUT it makes that custom subdirectory invisible alas, i'm still getting bugs when I try to keep it visible – iphigenie Mar 9 at 15:46
  • Maybe for the test site do downgrade to magento 2.4 and do 2.4.2 for the real site – Alain Stout Mar 9 at 15:54
1

Check that your webserver serves the requests from the proper location. it should be referencing the <magento_proj_folder>/pub folder as Document Root.

https://devdocs.magento.com/guides/v2.4/install-gde/tutorials/change-docroot-to-pub.html

enter image description here

Please check this answer https://magento.stackexchange.com/a/332399/35330 that can shed some light over the changes in the new upgrade which doesn't 'get along' with serving requests from the project subfolders.

Also see this thread, where I explained how you can update the directions of the virtual host and the urls inside Magento The requested URL /pub/ was not found on this server. - Magento .htaccess problem

5
  • Hi @Diana Botean , thanks so much , yes I was thinking bout sending you a message, because I was already reading your posts about this topic, but 1 thing, like I have 2 frontends, 1 is the main = www.takoda.shop , then 2 = the backup I work on with this new magento 2.4.2 update at www.takoda.shop/backup , so with dedicated virtual host, I cannot have 2 sites is what it looks like – Alain Stout Mar 9 at 14:35
  • yeah, the `<domain_name>/<folder_name>' doesn't work anymore. my best suggestion is that you create a virtual host for each instance and separate them entirely. – Diana Botean Mar 9 at 14:40
  • 2
    if it is for backup/testing purposes you kind of can, either by reverting these .htaccess and path changes (but has to be done every upgrade) or some work on rewrites. It's not a long term sustainable option. It also messes up if you had another app installed, eg wordpress – iphigenie Mar 9 at 14:56
  • Hi, I cannot find the chat, I'm experiential checking if it do works from root folder, 1 question how do you work an a site backup test, do you need an own server for that how others do that, cannot work on front site when visitors are there and also the command line deployment seems very slow with Magento 2.4.2 – Alain Stout Mar 11 at 11:28
  • well it depends on the case, usually, the clients i work with they have their own infrastructure and we build the staging/ preproduction/ test machine there. not all of them have an infrastructure of their own, others have cloud subscriptions and we do the test machine there. – Diana Botean Mar 11 at 11:31
1

Magento 2.4.2 is now serving all content from magento_root/pub most sites won't notice this change because of the rewrites in the 2.4.2 version of magento_root/.htaccess https://github.com/magento/magento2/commit/640cad53009b291334234ccd61ab79f256b43da2

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

These rewrites will have no effect on stores served from sub folders which will now be broken.

The simplest way to load one or more stores via url sub folders is to create the sub folder in magento_root/pub and symlink to the static pub folders/files.

For example

https://shop01.com/shop/

https://shop02.com/shop/

mkdir magento_root/pub/shop01
cd magento_root/pub/shop01
ln -s ../media media
ln -s ../static static
ln -s ../../pub pub
ln -s ../.htaccess .htaccess
ln -s ../health_check.php health_check.php

magento_root/pub/shop01/index.php

<?php
require realpath(__DIR__) . '/../../app/bootstrap.php';

switch ($_SERVER['HTTP_HOST']) {
    case 'shop01.com':
    case 'www.shop01.com':
        $params = $_SERVER;
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'shop01';
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
        $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
        $app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
        $bootstrap->run($app);
        break;
    case 'shop02.com':
    case 'www.shop02.com':
        $params = $_SERVER;
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'shop02';
        $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
        $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
        $app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
        $bootstrap->run($app);
        break;

    default:
        $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
        /** @var \Magento\Framework\App\Http $app */
        $app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
        $bootstrap->run($app);
    break;
}
0

You are missing the apache configuration for your specific magento domain. To create it, you create a file in /etc/apache2/sites-available/ named after your domain followed by .conf. In your case: /etc/apache2/sites-available/local.magento2.com.conf In that file, you have to set some values:

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  ServerName local.magento2.com
  DocumentRoot /var/www/html/magento
  <Directory /var/www/html/magento/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
  </Directory>
  ErrorLog /var/log/apache2/error.log
  LogLevel warn
  CustomLog /var/log/apache2/access.log combined
</VirtualHost>

To activate the config use the command:

sudo a2ensite local.magento2.com.conf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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