Search code examples
grailsurl-mapping

URL mapping in Grails


Suppose this is my URL:

https://stackoverflow.com/questions/ask/question1.xml

Currently in my UrlMappings.groovy I have `

"/$Question/$ask/$question1"(controller:"somecontroller")` to handle the request.

If my URL changes to:

https://stackoverflow.com/questions/ask/askAgain/question1.xml

my URL mapping cannot handle it.

Is there a way I can get ask/askAgain to be referenced by $ask in my urlmapping.groovy?


Solution

  • This is what I did to get around this. I changed my URLMapping to

    "/$Question/$ask**"(controller:"somecontroller")
    

    If my URL is :

    `http://stackoverflow.com/questions/ask/askAgain/question1.xml`
    

    So now, $ask** = ask/askAgain/question1.xml

    Then, If I want to remove question1.xml from that URL. I can use Regex to get rid of it.