title: Spring redirect from ErrorController
body: <p>I have a number of generic error pages which are used by multiple applications other than the one I have control of. I would like to configure the Spring Boot error controller to do a redirect to one of these pages. Unfortunately it's not working.</p>
  
  <p>Eg.</p>
  
  <pre><code>  @Controller  
    public class MyCustomErrorController implements ErrorController {
  
      @GetMapping(value = "/error")
      public String handleError(HttpServletRequest request) {
        Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
  
        if (status != null) {
          Integer statusCode = Integer.valueOf(status.toString());
  
          if (statusCode == HttpStatus.NOT_FOUND.value()) {
            return "redirect:https://www.example.com/error-404";
          }
        }
  
        return "redirect:https://www.example.com/error-500";
      }
  
      @Override
      public String getErrorPath() {
        return "/error";
      }
    }
  </code></pre>
  
  <p>If for example I purposefully mistype a URL I can see the response has the Location header with the 404 URL I am expecting but the browser doesn't actually redirect. Any ideas if it's possible to do a redirect from within a custom ErrorController?</p>
  
  <p>Could this be because I'm trying to test this from localhost, and Strict-Transport-Security is ignoring the response Location header value (which is on a FQDN)?</p>