views:

265

answers:

1

I'm currently doing my Grails 301 URL-redirects using the following quite cumbersome "servlet style" method:

def action = {
  ...
  if (shouldRedirect) {
    response.status = 301
    response.setHeader("Location", "http://url/to/redirect/to.html")
    render("")
    return false
  }
  ...
}

Is there any cleaner and more compact Groovy/Grails'y way to perform a 301 redirect?

Please note that I'm talking about 301 redirect, not the standard 302 redirects which can be achieved using the standard Grails redirect(...) mechanism.

+3  A: 

Not really, you can specify the status in the render call like render(status: 301) but you can't set the Location header that way.

mbrevoort