在 url 中写入 uri 模式



我正在使用带有scala的Play框架2.6,我想阻止从url访问我的网页。在通常情况下,如果我在 url 中编写 URI 模式,它将通过执行关联的操作重新编辑到网页,例如,如果我在 url 中写入:http://localhost:9000/home 它会重定向到主页,但我想要的是重定向到错误页面而不是编写 URI 时主页(在这种情况下:/home( 中的网址。

my routes file
GET  /home controllers.HomeController.index()

您可以在控制器方法中重定向:

# my routes file
GET  /home controllers.HomeController.errorRedirect()
# HomeController
...
def errorRedirect = Action {
Redirect("/error")
}

或者,也许您想捕获所有内容,然后重定向:

# my routes file
GET  /home controllers.HomeController.home()
GET  /*path controllers.HomeController.errorRedirect()

另请参阅:在播放文档中提供自定义错误处理程序。

最新更新