我在java中。这里的工作是做它在Java中的方法也许能够帮助
路线
GET / @controllers.ApplesController.index
GET /apples @controllers.ApplesController.home
GET /bananas @controllers.BananasController.home
GET /buybananas @controllers.BananasController.buy
控制器
@With(CheckUrl.class)
public static Result index() {
return ok(index.render("Unable to resolve host."));
}
CheckUrl.java
public class CheckUrl extends play.mvc.Action.Simple {
public F.Promise<SimpleResult> call(Http.Context ctx) throws Throwable {
String host = request().host();
System.out.println("HOST IS "+host);
if (host.equalsIgnoreCase("apples.com")) {
return F.Promise.pure(redirect("/apples"));
}else if (host.equalsIgnoreCase("bananas.com ")){
return F.Promise.pure(redirect("/bananas"));
}else if (host.equalsIgnoreCase("buy.bananas.com")){
return F.Promise.pure(redirect("/buybananas"));
}else{
return delegate.call(ctx);
}
}
I不知道它是否是这样做的好方法。我已经用request().uri()
试过了,但没有与request().host()
试过,这对我很有帮助。可能会有所帮助。
像这样的事情更好地由http服务器处理...不是由框架。不过,你可以实现一些这样的功能。有关更多详情,请参阅 - > http://typesafe.com/activator/template/play-multidomain-seed和https://github.com/adrianhurt/play-multidomain-seed/blob/master/app/Global.scala – 2015-02-05 20:26:32
@SarveshKumarSingh写一个答案而不是评论,这是点赞/接受 – biesior 2015-02-05 20:31:20
@biesior解决方案的范围不适合答案。需要了解的东西太多,需要以特定的方式创建整个项目。 – 2015-02-05 20:34:08