Search code examples
phpsymfonyyamlsymfony4

Symfony 4, conditional route redirect/override in PROD mode


The route of FosUserBundle '/login' must not be accessible in Production mode. It must redirect to the route '/choiceConnexion'.

I thought I had this working because in dev mode there is a redirect successfully taking place, using 'config/routes/dev/routes.yaml' in this mode. However when setting the env in prod, the redirect doesn't work.

I have tried putting similar confingurations in a config/routes/prod folder, thinking it would switch, however it doesn't work.

I assumed in Prod the first code snippet below woulc be called:

config/routes.yaml

home_choiceConnexion:
  path: /login
  controller: App\Controller\HomeController::choiceConnexion

The above doesn't work, however in dev, the rerouting taking place in config/dev/routes.yaml does work when the app is in dev mode.

fos_user_security_login:
  path: /softia/login
  controller: FOS\UserBundle\Controller\SecurityController::loginAction

The main difference is that '/login' already exists, so I think the rerouting doesn't get prioretized and doesn't override the route fos_user_security_login.

I need to achieve this redirection for a client's project and would be grateful of any help.


Solution

  • Update: I have delivered a git branched which seem to work, I simply used annotation on the controller to this effect and it seems there's no conflict with the '/login' from the fosUserBundle.

    Will update the post if this doesn't solve it.

    /**
         * @Route("/choiceConnexion", name="home_choiceConnexion")
         * @Route("/login")
         */