I am currently working on a filter in Grails that will allow me to redirect all incoming requests on foo.org to the same subpage on foo.com. So far I have been doing the following:
if(!(""+request.requestURL).toLowerCase().startsWith(
grailsApplication.config.grails.serverURL ))
{redirect(url:"${grailsApplication.config.grails.serverURL}${request.requestURI}",params:params) }
Unfortunately, I am experiencing several issues in this approach:
Use request.forwardURI
.
If you have meant GET params, then it should be resolved using the above URI?
I think 301 redirects are not possible using classic redirect
. You can do this in a filter like this, which is obviously not the cleanest way:
def filters = {
all(controller:'*', action:'*') {
before = {
if (request.serverName == "foo.org") {
response.setStatus(301);
response.setHeader("Location", "http://foo.com" + request.forwardURI)
response.flushBuffer()
return false; // return false, otherwise request is handled from controller
}
}
}
}