Question

This is probably a very simple problem but for the life of me I can't get it to work.

I need to redirect google requests for ajax generated code to return a html template for indexing

I have the following in my urlmappings.conf

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

However if I enter mysite?_escaped_fragment_=200 in the browser the controller is not called

If however I enter mysite_escaped_fragment=200 the controller is called and the action executed.

Any suggestions would be greatly appreciated.

Thanks Ash

Was it helpful?

Solution

You can not use '?' char in the route matching i.e. it will be ignored. Use this filter instead (put this class in the config folder w/ fileName 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'

            }
        }
    }
 }`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top