Grails Redirects include trailing slash

I am using Grails 2.3.6 and trying to redirect the url to include the trailing slash, but leave the rest of the url as it is. The reason is because I have dynamic content that will have images and attachments. I would like these images and attachments to appear as child pages of dynamic content, for example:

http://example.com/content

Points to a dynamically created piece of content, no problem. But, if I want to have an attachment, I will include a href link that points to attachments/file1.pdf. The problem is that in the example above it would create http://example.com/attachments/file1.pdf(note that it /content/was deleted).

I really want the path to look like this:

http://example.com/content/attachments/file1.pdf

I believe the best solution is to redirect URLs for content that includes a slash (if they are not already). Unfortunately, I continue to get stuck with errors or redirect loops.

I tried the following sentence: Grails UrlMapping Redirect to save DRY , but UrlMappings.groovy doesn't distinguish enough when I say that the same URL is two different places (the only difference is the trailing slash)

static mappings = {
    "/${content}/"(controller: "application", action: "index")
    "/${content}"(controller: "application", action: "redirectToAddSlash")
}

I also know that Grails 2.3 includes UrlMapping redirects, but the examples given do not include inline variables.

Ideally I would like to have something like this:

static mappings = {
    "/${content}/"(controller: "application", action: "index") <=== Has trailing slash
    "/${content}"(redirect: "/${content}/")                    <=== Redirect to include trailing slash
}

Thanks in advance for your help!

+4
source share
1 answer

, , .

<base> href URL- .

:

<base href="http://example.com/content">
+1

Source: https://habr.com/ru/post/1530503/


All Articles