Lan*_*ali 6 url seo grails url-mapping
在grails中创建URL的标准方法是:
<a href="${createLink(controller:'news', action: 'show', params: [id: news.id])}">${news.title}</a>
Run Code Online (Sandbox Code Playgroud)
生成网址: /news/show/102
我想要更多SEO友好的URL,如:
/news/102/this-is-the-hottest-news-today
Run Code Online (Sandbox Code Playgroud)
在Grails中最干净的方法是什么?我可以使用grails URLMapping映射/news/show/102到/news/102,但我如何创建像上面这样的完整URL?
Dav*_*wer 15
您可以将标题转换为如下参数:
name story: "/news/$id/$headline" {
controller = "news"
action = "show"
}
Run Code Online (Sandbox Code Playgroud)
这样你就可以用标题创建你的网址,映射仍然有用.您当然实际上不必使用将出现在控制器中的标题参数.上面的示例使用命名的URL映射,因此您可以说:
${createLink(mapping: "story", params: [id: 102, headline: 'this-is-the-hottest-news-today'])}
Run Code Online (Sandbox Code Playgroud)
您可能也对此插件感兴趣,可以创建规范网址 - http://www.grails.org/plugin/canonical
| 归档时间: |
|
| 查看次数: |
3082 次 |
| 最近记录: |