B4J Question How to hide webapp directory

Chris Guanzon

Active Member
Licensed User
Longtime User
Hello! How can I hide the web app directory or redirect it to another page if the user enters this "URL: domain.com/public/"?

The attached image is the directory under the www folder.

1656288500639.png
1656288578293.png
 

PaulMeuris

Active Member
Licensed User
So when the user types domain.com/public/ in the address bar of the browser you want to show a webpage in stead of the list of files?
This is what i usually do in php:
redirect to index page:
<?php
    header("Location: ../index.php");
?>
And then of course you have to provide an index.php file in the root folder.
Greetings,
Paul
 
Upvote 0

tummosoft

Member
Licensed User
Longtime User
(1) Create a Filter Server class

B4X:
'Filter class
Sub Class_Globals
    
End Sub

Public Sub Initialize
    
End Sub

'Return True to allow the request to proceed.
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
    If req.Secure Then
        Return True
    Else
        resp.SendRedirect(req.FullRequestURI.Replace("/public", "/your redirect"))
        'resp.SendRedirect(req.FullRequestURI.Replace("http:", "https:") _
       '.Replace(Main.srvr.Port, Main.srvr.SslPort))
        Return False
    End If
End Sub

(2) Add this line into Main class

B4X:
srvr.AddFilter("/public", "Your Filter Class", False)
 
Upvote 0

Chris Guanzon

Active Member
Licensed User
Longtime User
(1) Create a Filter Server class

B4X:
'Filter class
Sub Class_Globals
   
End Sub

Public Sub Initialize
   
End Sub

'Return True to allow the request to proceed.
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
    If req.Secure Then
        Return True
    Else
        resp.SendRedirect(req.FullRequestURI.Replace("/public", "/your redirect"))
        'resp.SendRedirect(req.FullRequestURI.Replace("http:", "https:") _
       '.Replace(Main.srvr.Port, Main.srvr.SslPort))
        Return False
    End If
End Sub

(2) Add this line into Main class

B4X:
srvr.AddFilter("/public", "Your Filter Class", False)

This works perfectly. Thanks a lot.
 
Upvote 0
Top