Is there a default catch all fallback route in Play framework? If so how can I configure it in my routes file? Currently, there are some urls that I do not want the user to call them and even if they call, I don't want that error page appearing, rather I want them to go to the landing page of my web app! Is there a way to do that in the routes configuration file?

有帮助吗?

解决方案

Simply define a route matching any path at the end of your routes file. Do not forget to define specific routes for your assets though, for example:

GET   /               controllers.Application.index
GET   /some/path      controllers.Application.someHandler
...

# End of file
GET   /favicon.ico    controllers.Assets.at(path="/public", file="img/favicon.ico") 
GET   /$file<(css|img|js|partials)/.*>    controllers.Assets.at(path="/public", file) 
GET   /$path<.*>      controllers.Application.catchall(path)

Any URL not matched by an earlier rule will be matched by this one.

其他提示

Catch all routes makes sense when you want to do something with the path (ie. resolve it manually in your custom action), otherwise it's enough to use common onHandlerNotFound in your Global object and redirect request wherever you want.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top