diff --git a/src/Controller/FacetBlockAjaxController.php b/src/Controller/FacetBlockAjaxController.php
index e7a6f9164ff27bc88ea9628527cfe9621529c0ba..28e2422506bc4e725b0825a491c70a37e9782044 100644
--- a/src/Controller/FacetBlockAjaxController.php
+++ b/src/Controller/FacetBlockAjaxController.php
@@ -117,12 +117,10 @@ class FacetBlockAjaxController extends ControllerBase {
 
     // Rebuild the request and the current path, needed for facets.
     $path = $request->request->get('facet_link');
-
-    // Remove base path if drupal is installed in a sub-directory.
+    $facets_blocks = $request->request->all()['facets_blocks'] ?? [];
     $host = $request->getSchemeAndHttpHost();
-    $base_url = $host . base_path();
+    $base_url = strpos($path, $host) ? $host . base_path() : base_path();
     $path = preg_replace('/^' . str_replace('/', '\/', $base_url) . '/', '/', $path);
-    $facets_blocks = $request->request->all()['facets_blocks'] ?? [];
 
     if (empty($path) || empty($facets_blocks)) {
       throw new NotFoundHttpException('No facet link or facet blocks found.');
