B4J Tutorial [ABMaterial] Add “root filter” to redirect visitors to site entry page

The common entry point for a ABMaterial webapp is the “Application Name” page or AppName in the code.

When you visit ABMaterial.com, the site redirects you to the entry page named “demo”


But what happens if we enter the site from the root?


Depending on the website configuration (e.g. htaccess ) visitors may see a new page hosted in the root folder, a 403 forbidden error, or other behavior.

Most likely the port specified in the URL (51042) will be dedicated to the ABMaterial webapp. Thus any visitors to the root can be gently redirected to the app entry page with a simple filter.

1. Add ROOTFILTER.BAS to your project. (See attached)
2. Change the AppName to the name of your web app.
3. Add the filter to StartServer and StartServerHTTP2 in ABMAPPLICATION.BAS
public Sub StartServer(srvr As Server, srvrName As String, srvrPort As Int) 
    ABM.WriteAppLauchPageToDisk(AppPage, File.DirApp & "/www/" & AppName, "index.html", ABMShared.NeedsAuthorization)
    ' start the server
    ' MTE, 10/18/2016
    ' Add root filter to redirect to site entry point
    srvr.AddFilter( "/", "RootFilter", False )
    srvr.AddFilter("/js/b4j_ws.min.js", "ABMSessionCreator", False)
    srvr.AddWebSocket("/ws/" & AppName, "ABMApplication")
    For i =0 To Pages.Size - 1
        srvr.AddWebSocket("/ws/" & AppName & "/" & Pages.Get(i) , Pages.Get(i))


  • RootFilter.bas
    401 bytes · Views: 305
Last edited: