symfony/routing · error · RuntimeException

Ambiguous redirection settings, use the "path" or "route"…

Error message

Ambiguous redirection settings, use the "path" or "route" parameter, not both: "%s" and "%s" found respectively in "%s" routing configuration.

What it means

RedirectController::__invoke() looks at the route's _route_params and throws a RuntimeException when both 'route' and 'path' keys are present, since the redirect cannot target both another route and a raw path. Exactly one must be configured.

Solutions

  1. Remove either the 'path' or the 'route' default from the redirect route definition
  2. Use 'route' + optional parameters to redirect to a named route
  3. Use 'path' (optionally with scheme/httpPort/httpsPort) to redirect to a raw URL path

Example fix

// before
defaults: { _controller: 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController', route: 'home', path: '/' }
// after
defaults: { _controller: 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController', route: 'home' }
Defensive patterns

Strategy: validation

Validate before calling

$defaults = $route->getDefaults();
if (isset($defaults['route'], $defaults['path'])) {
    throw new \InvalidArgumentException('Redirect route must define route or path, not both');
}

Try / catch

try {
    $response = $redirectController->__invoke($request);
} catch (\RuntimeException $e) {
    // report misconfigured redirect route
}

Prevention

When it happens

Trigger: A route annotation/attribute like #[Route(path: '/go', name: 'go', defaults: ['_controller' => RedirectController::class, 'path' => '/', 'route' => 'home'])] specifying both keys, or merged config accidentally combining both.

Common situations: Copy-pasting redirect route definitions and leaving a leftover 'path' while adding 'route' (or vice versa); config merging in multi-file route setups.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14). Data as JSON: /api/errors/5a5a9c66f0fc6eac. Report an issue: GitHub.

Appendix: source

Thrown at Controller/RedirectController.php:175

            }

            if (null !== $httpsPort && 443 != $httpsPort) {
                $port = ":$httpsPort";
            }
        }

        $url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$path.$qs;

        return new RedirectResponse($url, $statusCode);
    }

    public function __invoke(Request $request): Response
    {
        $p = $request->attributes->get('_route_params', []);

        if (\array_key_exists('route', $p)) {
            if (\array_key_exists('path', $p)) {
                throw new \RuntimeException(\sprintf('Ambiguous redirection settings, use the "path" or "route" parameter, not both: "%s" and "%s" found respectively in "%s" routing configuration.', $p['path'], $p['route'], $request->attributes->get('_route')));
            }

            return $this->redirectAction($request, $p['route'], $p['permanent'] ?? false, $p['ignoreAttributes'] ?? false, $p['keepRequestMethod'] ?? false, $p['keepQueryParams'] ?? false);
        }

        if (\array_key_exists('path', $p)) {
            return $this->urlRedirectAction($request, $p['path'], $p['permanent'] ?? false, $p['scheme'] ?? null, $p['httpPort'] ?? null, $p['httpsPort'] ?? null, $p['keepRequestMethod'] ?? false);
        }

        throw new \RuntimeException(\sprintf('The parameter "path" or "route" is required to configure the redirect action in "%s" routing configuration.', $request->attributes->get('_route')));
    }
}

View on GitHub (pinned to 83fa223250)