gpt4 book ai didi

url - Grails SEO 友好 URL

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:27:34 24 4
gpt4 key购买 nike

在 grails 中创建 URL 的标准方法是:

<a href="${createLink(controller:'news', action: 'show', params: [id: news.id])}">${news.title}</a>

生成 url: /news/show/102

我想要更多 SEO 友好的 URL,例如:

/news/102/this-is-the-hottest-news-today

在 Grails 中最简洁的方法是什么?我可以使用 grails URLMapping 将 /news/show/102 映射到 /news/102,但是我如何像上面那样创建完整的 URL?

最佳答案

您可以将标题变成这样的参数:

name story: "/news/$id/$headline" {
controller = "news"
action = "show"
}

这样您就可以创建带有标题的网址,并且映射仍然有效。当然,您实际上不必使用将出现在 Controller 中的标题参数。上面的示例使用命名 URL 映射,因此您可以说:

${createLink(mapping: "story", params: [id: 102, headline: 'this-is-the-hottest-news-today'])}

您可能也对这个用于创建规范 url 的插件感兴趣 - http://www.grails.org/plugin/canonical

关于url - Grails SEO 友好 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2357828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com