=== modified file 'src/com/goldencode/p2j/main/WebClientSpawner.java'
--- old/src/com/goldencode/p2j/main/WebClientSpawner.java	2025-06-26 15:55:02 +0000
+++ new/src/com/goldencode/p2j/main/WebClientSpawner.java	2025-07-03 14:17:42 +0000
@@ -437,7 +437,7 @@
          {
             String forwardedProto = config.getString(ConfigItem.PROXY_PROTOCOL, null);
             String webRoot = config.getString(ConfigItem.WEB_ROOT, null);
-            uri = getForwardedUri(forwardedProto, forwardedHost, webRoot);
+            uri = getForwardedUri(forwardedProto, forwardedHost, webRoot, port);
          }
 
          if (uri == null)
@@ -548,10 +548,25 @@
    /**
     * Get the external web client uri assigned by the reverse proxy server.
     * 
+    * @param    forwardedProto
+    *           The forwarded protocol of the reverse proxy server, this value must be https. 
+    * @param    forwardedHost
+    *           The reverse proxy server host address
+    * @param    webRoot
+    *           The assigned web root to the web client
+    * @param    port
+    *           The embedded web server port that started by the web client
+    * 
     * @return   The external uri of this web client
     */
-   private static String getForwardedUri(String forwardedProto, String forwardedHost, String webRoot)
+   private static String getForwardedUri(String forwardedProto, String forwardedHost, String webRoot, int port)
    {
+      if (webRoot != null && webRoot.isEmpty())
+      {
+         //the case of direct port mapping
+         webRoot = new StringBuilder().append(":").append(port).toString();
+      }
+
       URI uri = URI.create(forwardedProto + "://" + forwardedHost +  webRoot + "/");
       //rewrite uri
       return uri.toString();

=== modified file 'src/com/goldencode/p2j/main/WebClientsManager.java'
--- old/src/com/goldencode/p2j/main/WebClientsManager.java	2024-07-15 14:07:29 +0000
+++ new/src/com/goldencode/p2j/main/WebClientsManager.java	2025-07-03 13:07:47 +0000
@@ -210,6 +210,10 @@
     * it must be completed.
     */
    private final int connectionTestTimeout;
+   
+   /** Indicates that the host ports are mapped directly to the corresponding forwarded host */
+   private final boolean directPortMapping;
+   
    /**
     * Creates a unique instance per a standard P2J server.
     * 
@@ -232,6 +236,8 @@
       
       prefix = ConfigItem.PROXY_CLIENT_NAME_PREFIX.read("client");
       
+      directPortMapping = ConfigItem.DIRECT_PORT_MAPPING.read(Boolean.FALSE);
+      
       portsRestricted =  (to > from) && (from > 0);
       
       webClientSessions = new ConcurrentHashMap<Integer, WebAllocatedResources>();
@@ -541,10 +547,13 @@
       if (viaProxyServer)
       {
          StringBuilder webRootBuilder = new StringBuilder();
-         webRootBuilder.append("/");
-         webRootBuilder.append(proxyPathSegment);
-         webRootBuilder.append("/").append(
-                  hostsManager.getPortName(prefix, from, host, webClientConfig.getPort()));
+         if (!directPortMapping)
+         {
+            webRootBuilder.append("/");
+            webRootBuilder.append(proxyPathSegment);
+            webRootBuilder.append("/").append(
+                     hostsManager.getPortName(prefix, from, host, webClientConfig.getPort()));
+         }
          webRoot = webRootBuilder.toString();
       }
       webClientConfig.setNewClient(uuid, webRoot, osUser, forwardedProto, forwardedHost);

=== modified file 'src/com/goldencode/p2j/util/ConfigItem.java'
--- old/src/com/goldencode/p2j/util/ConfigItem.java	2025-04-04 08:58:01 +0000
+++ new/src/com/goldencode/p2j/util/ConfigItem.java	2025-07-03 13:18:14 +0000
@@ -312,6 +312,10 @@
    public static final ConfigItem<String> PROXY_CLIENT_NAME_PREFIX = 
       new ConfigItem<>(String.class, "portsRange/namePrefix", "", "", "", Type.WEB_CLIENT);
    
+   /** Indicates that the host ports are mapped directly to the corresponding forwarded host */
+   public static final ConfigItem<Boolean> DIRECT_PORT_MAPPING =
+      new ConfigItem<>(Boolean.class, "portsRange/directPortMapping", "client", "web", "directPortMapping", Type.WEB_CLIENT);
+   
    public static final ConfigItem<String> PROXY_CLIENT_PATH_SEGMENT =
       new ConfigItem<>(String.class, "proxyPathSegment", "", "", "", Type.WEB_CLIENT);
    

