Reputation: 50117
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.
Upvotes: 8
Views: 2654
Reputation: 5165
Yes, it's now possible to use redirect
and specify the permanent
parameter as true
as described here. For example:
redirect(url: "http://url/to/redirect/to.html", permanent: true)
Upvotes: 12
Reputation: 31280
The redirect
mechanism in Grails currently supports a permanent
parameter:
permanent
(optional) - If true the redirect will be issued with a 301 HTTP status code (permanently moved), otherwise a 302 HTTP status code will be issued
This should adequately solve your problem, and in a very Grails-y way.
Upvotes: 2