grailsactionhttp-status-code-404url-mappingwildcard-mapping

Grails: How do I map a 404 with /**


I've tried to create a custom 404 url mapping for URL's that are not found:

"/test" {
    controller="test"
}
"404" {
    controller="application"
    action="send404"
}
"500" {
    controller="application"
    action="send500"
}

But for some reason, the controller and action are never called. I get the default container 404 page. So, instead I tried:

"/test" {
    controller="test"
}
"/**" {
    controller="application"
    action="send404"
}
"500" {
    controller="application"
    action="send500"
}

Which seems to work fine, except that it also seems to call the send404 action on every request. For example, if I hit /test, I see the test page, but I also get the log statement I made in the send404() action.

Ideas appreciated...


Solution

  • Perhaps it's favicon.ico that's being requested by the browser on each request that's causing this to happen.

    // Route 404 to this action to see!
    def send404() {
    
        log.error("404 Page Not Found! " + request.forwardURI)
        response.status = 404;
        render(view:"/application/not-found.gsp")        
    }