#65994·symfony

[HttpFoundation] 308 responses do not get the 301 Cache-Control treatment

Author: nicolas-grekasCreated Sep 11, 2026Updated Sep 27, 2026
LabelsHttpFoundationRFC

Description

RedirectResponse::__construct() drops the default no-cache, private Cache-Control header for status 301 only:

https://github.com/symfony/symfony/blob/333cec4f7c294128dc2a73491fbaef3e39bf6d58/src/Symfony/Component/HttpFoundation/RedirectResponse.php#L45-L47

301 and 308 are both permanent redirects. The only difference is that 308 keeps the request method. Yet:

php
(new RedirectResponse('/target', 301))->headers->get('Cache-Control'); // null
(new RedirectResponse('/target', 302))->headers->get('Cache-Control'); // "no-cache, private"
(new RedirectResponse('/target', 307))->headers->get('Cache-Control'); // "no-cache, private"
(new RedirectResponse('/target', 308))->headers->get('Cache-Control'); // "no-cache, private"

This is reachable straight from the framework. RedirectController emits 308 whenever permanent: true meets keepRequestMethod: true:

https://github.com/symfony/symfony/blob/333cec4f7c294128dc2a73491fbaef3e39bf6d58/src/Symfony/Component/Routing/Controller/RedirectController.php#L79-L83

Same shape in urlRedirectAction() at L112-L116, and in FrameworkBundle's RedirectController on 6.4 (L84-L86 and L117-L119). So a route redirect declared permanent is cacheable when it does not keep the method and uncacheable when it does, which is not a distinction anyone configured.

Two ways to resolve the asymmetry, and I do not have a strong preference:

  1. Extend the 301 carve-out to 308, so both permanent codes behave the same.
  2. Leave it as is, on the grounds that the 301 carve-out is old behaviour we do not want to grow.

#59346 asked for the opposite change, removing the carve-out from 301 so browsers stop caching permanent redirects indefinitely, and was closed as by design: a permanent redirect is cacheable, that is what permanent means. That reasoning applies to 308 just as well, which argues for option 1. But it changes what anyone serving a 308 gets today, so it wants a deliberate call rather than a drive-by patch.

Which one do we want?