在Grails中,我試圖使它對/ images/*的任何請求實際上轉到另一個主機上的另一個網站。Grails UrlMappings到外部遠程文件
我知道如何使用Mod Rewrite在Apache中執行此操作,但是如何使用UrlMappings實現此目的?
我想
/圖像/ *去http://somedomain/images/ *
在Grails中,我試圖使它對/ images/*的任何請求實際上轉到另一個主機上的另一個網站。Grails UrlMappings到外部遠程文件
我知道如何使用Mod Rewrite在Apache中執行此操作,但是如何使用UrlMappings實現此目的?
我想
/圖像/ *去http://somedomain/images/ *
你不能直接。您必須將其映射到控制器,該控制器將依次將redirect
移動到所需的位置。喜歡的東西:
"/images/$urlTail**" (controller: "image", action: "external")
然後在ImageController
的external
方法:
def actualUri = request.forwardURI.replace("/images/", "")
redirect "http://example.com/" + actualUri;
另一種解決方法,我發現:
String url = <your-url>
java.net.URI uri = new java.net.URI(url)
return Response.seeOther(uri).build()
沒有更簡單的方法?如果不是,你能展示如何通過尾巴作爲參數嗎? – 2011-01-18 21:32:54