B4J Question www in URL with secure site

Discussion in 'B4J Questions' started by aaronk, Jul 31, 2019.

  1. aaronk

    aaronk Well-Known Member Licensed User


    I have my B4J server running a web server.

    I have followed the tutorial:

    I have also enabled a SSL certificate on it and working fine.

    If the customer opens the website like https://mysite.com it loads the site fine. If they open http://mysite.com it converts to https://mysite.com and this is also working fine.

    So the above works fine.

    However, if they open www.mysite.com it comes up saying the site is not secure..

    Is there a way in making it if the user type www.mysite.com to redirect it to https://mysite.com (so it removes www. part) ?
  2. jimmyF

    jimmyF Active Member Licensed User

    I believe that you will need to add "www.mysite.com" to your certificate.

    Or, have a separate site with an automatic redirect to your secure site.

  3. Jorge M A

    Jorge M A Active Member Licensed User

  4. MarkusR

    MarkusR Well-Known Member Licensed User

    maybe you can setup some rules in the .htaccess file.
    Jorge M A likes this.
  5. aaronk

    aaronk Well-Known Member Licensed User

    Yeah I have the https filter already.

    I have made a small change to the script and seems to be working fine from the tests I have done, and not 100% if it's the best way in doing this but thought I would share in case someone else wants to know how I managed to get it to work:

    Public Sub Filter(req As ServletRequest, resp As ServletResponseAs Boolean
    If req.Secure Then
    If req.FullRequestURI.StartsWith("www."Or req.FullRequestURI.StartsWith("https://www."Then
    Dim url As String = req.FullRequestURI
    Return False
    End If
    Return True
    If req.FullRequestURI.StartsWith("www."Or req.FullRequestURI.StartsWith("http://www."Then
    Dim url As String = req.FullRequestURI
                url = url.Replace(
                url = url.Replace(
    "http:""https:") _
                   .Replace(Main.srvr_public.Port, Main.srvr_public.SslPort))
    Return False
    End If
    "http:""https:") _
           .Replace(Main.srvr_public.Port, Main.srvr_public.SslPort))
    Return False
    End If
    End Sub
    Based on the above, if someone goes to http://www.mysite.com or https://www.mysite.com or www.mysite.com it will change it to https://mysite.com
    Jorge M A, OliverA and universengo like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice