Repository: quarkusio/quarkus
Issue: Access log logged twice if non-root path is a prefix of root path

### Describe the bug

Original - https://github.com/smallrye/smallrye-health/issues/412#issuecomment-1272883427.

We need to distinguish cases where either of the paths is mapped to "/" (root/main router), if one is a subpath of another, or if they are totally different.

TBH, I'm thinking the best would be to log everything under "/". So the question is whether it makes sense to log for instance GET /whatever if the quarkus.http.root-path=/app. Not for me to decide but I'll mention it in the PR.

### Expected behavior

_No response_

### Actual behavior

_No response_

### How to Reproduce?

_No response_

### Output of `uname -a` or `ver`

_No response_

### Output of `java -version`

_No response_

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

_No response_

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

_No response_

### Additional information

_No response_

Changed files:
extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/VertxHttpProcessor.java
extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java

diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/VertxHttpProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/VertxHttpProcessor.java
index ef861524db7..0380a2925ed 100644
--- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/VertxHttpProcessor.java
+++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/VertxHttpProcessor.java
@@ -312,9 +312,8 @@ ServiceStartBuildItem finalizeRouter(
                 defaultRoute.map(DefaultRouteBuildItem::getRoute).orElse(null),
                 listOfFilters, vertx.getVertx(), lrc, mainRouter, httpRouteRouter.getHttpRouter(),
                 httpRouteRouter.getMutinyRouter(), httpRouteRouter.getFrameworkRouter(),
-                nonApplicationRootPathBuildItem.isDedicatedRouterRequired(),
-                nonApplicationRootPathBuildItem.isAttachedToMainRouter(),
                 httpRootPathBuildItem.getRootPath(),
+                nonApplicationRootPathBuildItem.getNonApplicationRootPath(),
                 launchMode.getLaunchMode(),
                 !requireBodyHandlerBuildItems.isEmpty(), bodyHandler, gracefulShutdownFilter,
                 shutdownConfig, executorBuildItem.getExecutorProxy());
diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java
index fb2249f0335..b596cee278f 100644
--- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java
+++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxHttpRecorder.java
@@ -341,8 +341,8 @@ public void finalizeRouter(BeanContainer container, Consumer<Route> defaultRoute
             LiveReloadConfig liveReloadConfig, Optional<RuntimeValue<Router>> mainRouterRuntimeValue,
             RuntimeValue<Router> httpRouterRuntimeValue, RuntimeValue<io.vertx.mutiny.ext.web.Router> mutinyRouter,
             RuntimeValue<Router> frameworkRouter,
-            boolean nonApplicationDedicatedRouter, boolean nonApplicationAttachedToMainRouter,
-            String rootPath, LaunchMode launchMode, boolean requireBodyHandler,
+            String rootPath, String nonRootPath,
+            LaunchMode launchMode, boolean requireBodyHandler,
             Handler<RoutingContext> bodyHandler,
             GracefulShutdownFilter gracefulShutdownFilter, ShutdownConfig shutdownConfig,
             Executor executor) {
@@ -560,10 +560,17 @@ public void handle(HttpServerRequest event) {
             }
             AccessLogHandler handler = new AccessLogHandler(receiver, accessLog.pattern, getClass().getClassLoader(),
                     accessLog.excludePattern);
-            if (nonApplicationDedicatedRouter && !nonApplicationAttachedToMainRouter) {
+            if (rootPath.equals("/") || nonRootPath.equals("/")) {
+                mainRouterRuntimeValue.orElse(httpRouterRuntimeValue).getValue().route().order(Integer.MIN_VALUE)
+                        .handler(handler);
+            } else if (nonRootPath.startsWith(rootPath)) {
+                httpRouteRouter.route().order(Integer.MIN_VALUE).handler(handler);
+            } else if (rootPath.startsWith(nonRootPath)) {
+                frameworkRouter.getValue().route().order(Integer.MIN_VALUE).handler(handler);
+            } else {
+                httpRouteRouter.route().order(Integer.MIN_VALUE).handler(handler);
                 frameworkRouter.getValue().route().order(Integer.MIN_VALUE).handler(handler);
             }
-            httpRouteRouter.route().order(Integer.MIN_VALUE).handler(handler);
 
             quarkusWrapperNeeded = true;
         }