Domain routes in Play Framework 2.3

Daniel Lang

I want to point multiple subdomains and/or root domains to a single Play Framework 2.3 (Scala) application, for example apples.com, bananas.com or buy.bananas.com.

Depending on which domain the request comes in, I want to have different routes.

Ideally, it should work something like this:

GET    apples.com        @controllers.ApplesController.home
GET    bananas.com       @controllers.BananasController.home
GET    buy.bananas.com   @controllers.BananasController.buy

Is there any way to do this in Play Framework 2.3?

singhakash

I am working in java .Here is the way to do it in java maybe that could help

routes

GET    /             @controllers.ApplesController.index
GET    /apples       @controllers.ApplesController.home
GET    /bananas      @controllers.BananasController.home
GET    /buybananas   @controllers.BananasController.buy

controller

@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 dont know if it the good way of doing it.I have tried it with request().uri() but not with request().host() and that worked for me.Maybe that could help.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Long dynamic routes in play framework 2

From Dev

How to "rewrite" urls or routes with Play Framework 2

From Dev

Play framework routes

From Dev

Play framework 2 : How to pass object between routes, views, and controller?

From Dev

play framework - bind enum in routes

From Dev

Play Framework, REST, Routes, and Controllers

From Dev

Scala backticks in Play Framework Routes

From Dev

Play Framework Error in Routes file

From Dev

Play framework: redirect to a different domain

From Dev

Non-capturing wildcards in Play Framework routes

From Dev

Using POST routes parameters in Play Framework

From Dev

Iterating all Play Framework routes in Test

From Dev

split routes in multiple files for play framework 2.2

From Dev

Play Framework @routes.Assets.at Compilation Error

From Dev

Play framework - call controller in routes with Class parameter

From Dev

Play framework routes, and scala predef values

From Dev

Play Framework 2.3.4 routes redirection to subproject

From Dev

Non-capturing wildcards in Play Framework routes

From Dev

Using POST routes parameters in Play Framework

From Dev

Play framework - call controller in routes with Class parameter

From Dev

Play Framework 2.3.4 routes redirection to subproject

From Dev

Objectify with Play Framework 2

From Dev

Play 2 - Access conf property in routes file

From Dev

Syntax highlighting for scala.html and routes files in IntelliJ / Play framework

From Dev

Play Framework. Routes. Error: "not enough arguments for method at..."

From Dev

Play Framework: split routes in multiple files without sub projects

From Dev

How to use imports and implicits in Play Framework's routes file?

From Dev

how to define optional path parameters in Play Framework routes

From Dev

Play Framework & IntelliJ - Cannot resolve symbol index/routes

Related Related

  1. 1

    Long dynamic routes in play framework 2

  2. 2

    How to "rewrite" urls or routes with Play Framework 2

  3. 3

    Play framework routes

  4. 4

    Play framework 2 : How to pass object between routes, views, and controller?

  5. 5

    play framework - bind enum in routes

  6. 6

    Play Framework, REST, Routes, and Controllers

  7. 7

    Scala backticks in Play Framework Routes

  8. 8

    Play Framework Error in Routes file

  9. 9

    Play framework: redirect to a different domain

  10. 10

    Non-capturing wildcards in Play Framework routes

  11. 11

    Using POST routes parameters in Play Framework

  12. 12

    Iterating all Play Framework routes in Test

  13. 13

    split routes in multiple files for play framework 2.2

  14. 14

    Play Framework @routes.Assets.at Compilation Error

  15. 15

    Play framework - call controller in routes with Class parameter

  16. 16

    Play framework routes, and scala predef values

  17. 17

    Play Framework 2.3.4 routes redirection to subproject

  18. 18

    Non-capturing wildcards in Play Framework routes

  19. 19

    Using POST routes parameters in Play Framework

  20. 20

    Play framework - call controller in routes with Class parameter

  21. 21

    Play Framework 2.3.4 routes redirection to subproject

  22. 22

    Objectify with Play Framework 2

  23. 23

    Play 2 - Access conf property in routes file

  24. 24

    Syntax highlighting for scala.html and routes files in IntelliJ / Play framework

  25. 25

    Play Framework. Routes. Error: "not enough arguments for method at..."

  26. 26

    Play Framework: split routes in multiple files without sub projects

  27. 27

    How to use imports and implicits in Play Framework's routes file?

  28. 28

    how to define optional path parameters in Play Framework routes

  29. 29

    Play Framework & IntelliJ - Cannot resolve symbol index/routes

HotTag

Archive