简体   繁体   中英

Symfony: routing with subdomain --> 404 error

I'm new with Symfony (5.3) and i'm trying to use the EasyAdmin^3 package and its controller.

class DashboardController extends AbstractDashboardController
{
    /**
     * @Route("/admin", name="admin")
     */
    public function index(): Response
    {
        //return parent::index();
        $routeBuilder = $this->get(AdminUrlGenerator::class);
        $url = $routeBuilder->setController(BookCrudController::class)->generateUrl();
        return $this->redirect($url);
    }

    public function configureDashboard(): Dashboard
    {
     ...
    }
    ....

In security.yaml, there is no access control:

access_control:
        # - { path: ^/admin, roles: ROLE_ADMIN }

I tried on my computer with

>symfony server:start -d
>symfony open:local

The URL http://127.0.0.1:8000/admin works

But on my server https://subdomain.domain.com/admin it doesn't work (error 404). But the route is configuring:

>php bin/console debug:router
admin                      ANY      ANY      ANY                             /admin

the URL to wasn't redirected to /public/ I added in / directory .htaccess file

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^(.*)$ public/index.php?$1 [L,QSA]

and added .htaccess in /public/

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

And then the /admin was forbidden, then I added in DashboardController file / function configureDashboard()

return Dashboard::new()
          ->disableUrlSignatures()
          ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM