Thomas
Thomas

Reputation: 1701

How to not URL encode a route parameter?

I am using Play 2.4 with Java, and I've got this route:

GET /page/:slug controllers.Application.page(slug: String)

So, for instance, if slug = this-is-a-slug, there's no problem, the route looks like this:

/page/this-is-a-slug

But, if slug = first-part-of-the-slug/second-part-of-the-slug, the URL bar shows:

/page/first-part-of-the-slug%2Fsecond-part-of-the-slug

I'd like to avoid encoding the slug, knowing that the number of slug 'parts' is undefined, and keep the slug as a unique parameter.

How could I do that? Any help appreciated.

Upvotes: 2

Views: 654

Answers (1)

Andriy Kuba
Andriy Kuba

Reputation: 8263

You need to use "*" like:

/page/*slug

Look for the "Dynamic parts spanning several /" section in the documentation https://www.playframework.com/documentation/2.4.x/JavaRouting

If you want a dynamic part to capture more than one URI path segment, separated by forward slashes, you can define a dynamic part using the * id syntax, which uses the .* regular expression:

GET   /files/*name       controllers.Application.download(name)

Here, for a request like GET /files/images/logo.png, the name dynamic part will capture the images/logo.png value.

Upvotes: 3

Related Questions