If you're on 2.4.2 it's the magento-in-subfolder issue with the new .htaccess settings
The [magento_root]/index.php file has been removed, and Magento now runs from /pub by default for Apache configurations. Stores that are served from subfolders will not work as expected and may display 404 errors
The installation instructions bin/magento setup:install
still give an example with a subfolder I flagged it on github months ago :(
simplest, if you are just starting:
- reinstall but not in a subfolder
- make the pub/ folder the server root
- things also work if you make the magento install main folder the document root, there's a config option
If you can change the document root (essentially losing your subfolder)
if you control your server config, don't need multiple apps in one instance, and don't want a "URL key" for the shop, just change the apache configuration to make the 'document root' be the pub folder in your magento install
things also work if you make the magento install main folder the document root, old style way, there's a config option
if you still want to have a url path showing for the shop, the workaround is simlinks inside the pub folder as per https://devdocs.magento.com/guides/v2.4/release-notes/open-source-2-4-2.html#known-issues
If you can't make pub or magento the document root:
simplest remains reinstall Magento (or move it) to your doc root.
Otherwise You will need to tweak your root .htaccess rewrites to pass things to the pub/ folder not the main folder
I banged my head on walls with that one but found that on my system it works IF I MADE THE FOLDER name different from the URL structure path. i.e. if you want "myshop" in the URL then create a folder called, say, "myshop-folder". (or have no URL but a subfolder)
These are answers I gave in post https://magento.stackexchange.com/posts/332405 in March but should still work
subfolder install that is invisible 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} /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} !^/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
.../magento-root
directory, and you should not edit.htaccess
file. Could you add your apache's vhost config to the question?magento-practice
as the root of the magento2 base which made URLhttp://localhost/magento-practice
.