Search code examples
grailsurl-rewritingurl-mapping

Grails UrlMappings to external remote files


In Grails, I'm trying to make it so that any requests to /images/* actually goes to another website on another host.

I know how to do it in Apache with Mod Rewrite, but how can I achieve this with UrlMappings?

I want

/images/* to go to http://somedomain/images/*


Solution

  • You can't directly. You'll have to map it to a controller which will in turn redirect to the desired location. Something like:

    "/images/$urlTail**"  (controller: "image", action: "external")
    

    And then in the external method of the ImageController:

    def actualUri = request.forwardURI.replace("/images/", "")
    redirect "http://example.com/" + actualUri;