From 8d35c1dde2e2330578c82d4b74b3ea8197a032af Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandrocelaya@gmail.com>
Date: Wed, 8 Nov 2023 09:06:12 +0100
Subject: [PATCH] Fix short URL visits deletion when multi-segment slugs are
 enabled

---
 CHANGELOG.md                      | 1 +
 config/autoload/routes.config.php | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d0f03e72..e667fd19 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
 ### Fixed
 * [#1819](https://github.com/shlinkio/shlink/issues/1819) Fix incorrect timeout when running DB commands during Shlink start-up.
 * [#1901](https://github.com/shlinkio/shlink/issues/1901) Do not allow short URLs with custom slugs containing URL-reserved characters, as they will not work at all afterward.
+* [#1900](https://github.com/shlinkio/shlink/issues/1900) Fix short URL visits deletion when multi-segment slugs are enabled.
 
 
 ## [3.6.4] - 2023-09-23
diff --git a/config/autoload/routes.config.php b/config/autoload/routes.config.php
index ea305d86..051e18dd 100644
--- a/config/autoload/routes.config.php
+++ b/config/autoload/routes.config.php
@@ -32,8 +32,11 @@ return (static function (): array {
             ...ConfigProvider::applyRoutesPrefix([
                 Action\HealthAction::getRouteDef(),
 
-                // Visits
+                // Visits.
+                // These routes must go first, as they have a more specific path, otherwise, when multi-segment slugs
+                // are enabled, routes with a less-specific path might match first
                 Action\Visit\ShortUrlVisitsAction::getRouteDef([$dropDomainMiddleware]),
+                Action\ShortUrl\DeleteShortUrlVisitsAction::getRouteDef([$dropDomainMiddleware]),
                 Action\Visit\TagVisitsAction::getRouteDef(),
                 Action\Visit\DomainVisitsAction::getRouteDef(),
                 Action\Visit\GlobalVisitsAction::getRouteDef(),
@@ -54,7 +57,6 @@ return (static function (): array {
                 ]),
                 Action\ShortUrl\EditShortUrlAction::getRouteDef([$dropDomainMiddleware]),
                 Action\ShortUrl\DeleteShortUrlAction::getRouteDef([$dropDomainMiddleware]),
-                Action\ShortUrl\DeleteShortUrlVisitsAction::getRouteDef([$dropDomainMiddleware]),
                 Action\ShortUrl\ResolveShortUrlAction::getRouteDef([$dropDomainMiddleware]),
                 Action\ShortUrl\ListShortUrlsAction::getRouteDef(),