1

这可能是一个非常简单的问题,但对于我的生活,我无法让它发挥作用。

我需要重定向 ajax 生成代码的 google 请求以返回用于索引的 html 模板

我的 urlmappings.conf 中有以下内容

"/?_escaped_fragment_=$id"(controller:"google",action:"getOfferDetails")

但是,如果我在浏览器中输入 mysite?_escaped_fragment_=200 ,则不会调用控制器

但是,如果我输入 mysite_escaped_fragment=200 ,则会调用控制器并执行操作。

任何建议将不胜感激。

谢谢灰

4

1 回答 1

1

你不能使用'?路由匹配中的字符,即它将被忽略。请改用此过滤器(将此类放在带有文件名 CrawlerFilters.groovy 的配置文件夹中):

class CrawlerFilters {
 def filters = {
    google(controller: '*', action: '*') {
        before = {
            boolean isCrawler = webRequest.params._escaped_fragment_ != null
            if (isCrawler && !request._alreadyForwarded) {
                request._alreadyForwarded = true
                forward controller: 'google', action: 'getOfferDetails'

            }
        }
    }
 }`
于 2013-11-06T22:18:27.687 回答