.htaccess and Symfony 5 in hosted environment in subfolder

I am yet again trying to debug my mess of .htaccess files, this time in a Symfony 5 app.

The situation

On my domain example.com, I have the folder structure

/public_html
    /.htaccess
    /some_smaller_project
    /my_symfony_project
        /.htaccess
        /public
            /.htaccess
            /index.php
            /bundles
                /easyadmin
                    /app.css
                    /...
        /config, vendor, src, etc.
    /wp-admin
    /...

The site is in a hosted environment, i.e. I can’t access the server settings directly but have to use .htaccess.

The file my_symfony_project/config/routes/annotations.yaml contains

controllers:
    resource: ../../src/Controller/
    type: annotation
    prefix: /my_symfony_project
kernel:
    resource: ../../src/Kernel.php
    type: annotation

The file my_symfony_project/.htaccess contains

RewriteEngine On
RewriteBase /my_symfony_project/

RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [QSA, L]

The file my_symfony_project/public/.htaccess is an exact copy of the default htaccess recommended by the Symfony project.

The problem

The requests for example.com/my_symfony_project and example.com/my_symfony_project/some_route that are defined in my Controller classes work just fine, but the assets just return 404 codes.

Among the requests that throw 404 are:

example.com/bundles/easyadmin/app.css
example.com/bundles/easyadmin/app.js
example.com/_wdt/8b8d34    

So why do EasyAdmin and the Symfony Debug Toolbar look for assets at the wrong place? And how can I avoid other problems of the same type?

I promise I have searched for solutions to exactly this problem, but most places are either giving quick snippets for an htaccess file or assume access to http.conf

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 1

Your email address will not be published. Required fields are marked *


Grant W

Grant W

Try running php bin/console assets:install