Redirect non-www URLs

Splash Forums Rewrite Users Redirect non-www URLs

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  rocotocloc 6 hours, 8 minutes ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27689

    rocotocloc
    Participant

    Hello,

    I want to force my users to always use the ‘www’ URL style in my application but I cannot find the solution.

    If some particular user types http://myname.com I want to automatically redirect him to http://www.myname.com. Of course this must be done for all kinds of sub-paths in the real page.

    Could you please help me?

    Thank you very much.

    • This topic was modified 2 days, 9 hours ago by  rocotocloc.
    #27692

    You could try something similar to this:

    
    .addRule()
    .when(Not.any(Domain.matches("www.myname.com")))
    .perform(new HttpOperation() {
       @Override 
       public void performHttp(HttpServletRewrite event, EvaluationContext context) {
    
          String newUrl = event.getInboundAddress().toString()
                   .replace("myname.com", "www.myname.com");
    
          Redirect.temporary(newUrl).performHttp(event, context);
    
       }
    })
    

    I didn’t test it, but it shows the idea. You can use the Domain condition, but the operation requires some custom code. Which certainly can be improved. 😉

    #27693

    rocotocloc
    Participant

    I’ll give it a try.

    Thank you 😀

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

You must be logged in to reply to this topic.

Comments are closed.