title: Redirect with 301 status in Spring MVC 4 without ModelAndView
body: <p>I try to have a redirect with <code>301 Status Code</code> (you know I want to be SEO friendly etc). </p>
  
  <p>I do use <code>InternalResourceViewResolver</code> so I wanted to use some kind of a code similar to <code>return "redirect:http://google.com"</code> in my Controller. 
  This though would send a <code>302 Status Code</code></p>
  
  <p>What I have tried is using a <code>HttpServletResponse</code> to set header</p>
  
  <pre><code>@RequestMapping(value="/url/{seo}", method = RequestMethod.GET)
  public String detail(@PathVariable String seo, HttpServletResponse response){
      response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      return "redirect:http://google.com";
  }
  </code></pre>
  
  <p>It does still return <code>302</code>. </p>
  
  <p>After checking documentation and Google results I've come up with the following: </p>
  
  <pre><code>@RequestMapping(value="/url/{seo}", method = RequestMethod.GET)
  public ModelAndView detail(@PathVariable String seo){
      RedirectView rv = new RedirectView();
      rv.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
      rv.setUrl("http://google.com");
      ModelAndView mv = new ModelAndView(rv);
      return mv;
  }
  </code></pre>
  
  <p>It does work perfectly fine and as expected, returning code <code>301</code></p>
  
  <p>I would like to achieve it without using ModelAndView (Maybe it's perfectly fine though). Is it possible? </p>
  
  <p>NOTE: included snippets are just parts of the detail controller and redirect does happen only in some cases (supporting legacy urls). </p>