Create subdomain in Rewrite? Like http://tester12345.domain.com

Splash Forums Rewrite Users Create subdomain in Rewrite? Like http://tester12345.domain.com

This topic contains 5 replies, has 3 voices, and was last updated by  Lincoln Baxter III 1 year, 7 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #26668

    vished
    Participant

    Dear all,

    I want to create following scenario:

    1. Step:
    LoginPage: The user will login into the web portal.
    Each user has an username. For example tester12345
    This username is stored in the database.

    2. Step:
    After the redirect from the login page, all pages should be in this format:
    http://tester12345.domain.com/.......

    This means: {username}.domain.com/…..

    How can I do this?
    Thank you for your help.

    #26670

    Basically you will have to create an outbound rule which creates absolute URLs from the relative paths that are usually created by the container. So basically something like this:

    .addRule()
    .when(Direction.isOutbound())
    .perform(new HttpOperation() {
       @Override
       public void performHttp(HttpServletRewrite event, EvaluationContext context)
       {
          
          String oldUrl = event.getAddress().toString();
          String newUrl = ...;
          
          Substitute.with(newUrl).perform(event, context);
          
       }
    })
    
    #26672

    vished
    Participant

    Thank you for your reply.
    I tried something with your code but it doesn´t work.

    How should looks the String newUrl ?
    Currently my URL is: http://localhost:8080/my-app/

    But now I want to have http://tester12345.localhost:8080/
    In the production application the URL should be:
    http://tester12345.mydomain.com/

    tester12345 should be dynamic. This is the username which comes from the database.
    Thank you for your help

    #26679

    You could read the hostname from the HttpServletRequest and simply reuse the one from the original request. This should work fine and you will get different URLs in production and development.

    #26699

    What isn’t working? Could you be more specific about the problem?

    There is an example that might help you: http://ocpsoft.org/rewrite/examples/#section-2

    #26700
    .addRule()
    .when(
       Domain.matches("{testerId}.domain.com").and(Direction.isOutbound())
    )
    .perform(new HttpOperation() {
       @Override
       public void performHttp(HttpServletRewrite event, EvaluationContext context)
       {
          // Something like this... it needs to be changed to fit your exact scenario
          String oldUrl = event.getAddress().toString();
          String newUrl = Parameters.retrieve(context, "testerId") + "." + oldUrl;
          
          Substitute.with(newUrl).perform(event, context);
          
       }
    })
    )

    Etc.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Comments are closed.