2013-11-25 27 views
1

將Grails應用程序從版本2.2.2升級到2.3.2並最終升級到2.3.3後,我注意到一些以前工作的鏈接,現在返回一個404狀態。Grails 2.3.2/.3升級 - 無法映射以.html結尾的網址

爲了說明,這裏的樣品鏈接以及相應的URL映射條目最初在V2.2.2工作:

http://localhost:7080/pages/mytestpage 
http://localhost:7080/pages/mytestpage.html 

UrlMappings.groovy

static mappings = { 
    "pages/mytestpage"(controller: 'testController', action: 'testAction') 
} 

升級後,在給定的鏈接中,下面的鏈接不再起作用(即與.html鏈接):

解決此問題的210
http://localhost:7080/pages/mytestpage.html 

一種方式是由URLMappings項改爲如下:

UrlMappings.groovy(修改)

static mappings = { 
    "pages/mytestpage(.$format)?"(controller: 'testController', action: 'testAction') 
} 

我的問題是,是否有辦法解決此問題而無需更新URLMappings條目?任何能夠解釋這種映射在2.2.2版本中如何工作的人都會很有幫助。謝謝!

UPDATE

使用(html的)?而不是(。$格式)? UrlMappings.groovy中的也可以正常使用。

此外,在這個例子中,應用程序服務器被直接命中並且不使用web服務器。

回答

3

在Grails 2.2.x中,grails.mime.file.extensions = true設置以及grails.mime.types控制着URL中的擴展名。基本上,Grails忽略了MIME類型中列出的擴展名,並將URL映射到控制器(這就是爲什麼mytestpage.html起作用,而不是mytestpage.exe和mytestpage.anything)

看起來上述行爲是更改Grails 2.3.x +以支持REST改進。即使在URLMappings.groovy默認映射已accrodingly

//Grails 2.2.x 
"/$controller/$action?/$id?"{ 
    constraints { 
     // apply constraints here 
    } 
} 

改爲

//Grails 2.3.x 
"/$controller/$action?/$id?(.${format})?"{ 
    constraints { 
     // apply constraints here 
    } 
} 

您的解決方案似乎是解決這個問題

+0

你的答案幫助我更好地理解這個概念的正確方法。謝謝。 –