Reputation: 50117
Consider the following Grails URL mapping:
class UrlMappings {
static mappings = {
"/something/${foo_id}/" {
controller = "foo"
action = "bar"
}
}
When generating URL:s using g:link
..
<g:link controller="foo" action="bar" params="[foo_id: 123]">foobar</g:link>
.. the resulting link looks like ..
<a href="/something/123">foobar</a>
Note that the ending slash in the URL mapping is removed.
However, both the URL:s /something/123
and /something/123/
still work.
Due to the requirements of the application I'm building I must make "ends with slash"-version of the URL the primary one. Ideally I'd like to make the URL not ending with slash return a 404 (to avoid canonical page issues).
What is the best and most general way to make Grails create URL:s where ending slashes are not removed as described above?
One way to solve it would be to create all URL:s manually, but I do not want to go that way.
Upvotes: 1
Views: 774
Reputation: 10848
If you are looking for a way to create a groovy tag, that always add slash(/) add the end of the url, your best bet is to create a grails custom tagLib which create links, like the way g:link do.
But I don't know if that stops navigating by the link with out the slash.
Upvotes: 1
Reputation: 7685
Unfortunately grails URL mapping mechanism is not that sophisticated. So while forward URL mapping will work well (that is from URL to the controller) the reverse must be done manually to achive the described outcome.
Probably the best approach would be to create your own tag to output the desired links.
Upvotes: 5