diff --git a/.ht.router.php b/.ht.router.php
index b5884ef4a9d0fce4ea29e06c4e8e057af68bb230..97c517f0ca26a05f0a26977c3401880e97e44702 100644
--- a/.ht.router.php
+++ b/.ht.router.php
@@ -44,7 +44,7 @@
   // fallback to index.php.
   do {
     $path = dirname($path);
-    if (preg_match('/\.php$/', $path) && is_file(__DIR__ . $path)) {
+    if (str_ends_with($path, '.php') && is_file(__DIR__ . $path)) {
       // Discovered that the path contains an existing PHP file. Use that as the
       // script to include.
       $script = ltrim($path, '/');
diff --git a/core/assets/scaffold/files/ht.router.php b/core/assets/scaffold/files/ht.router.php
index b5884ef4a9d0fce4ea29e06c4e8e057af68bb230..97c517f0ca26a05f0a26977c3401880e97e44702 100644
--- a/core/assets/scaffold/files/ht.router.php
+++ b/core/assets/scaffold/files/ht.router.php
@@ -44,7 +44,7 @@
   // fallback to index.php.
   do {
     $path = dirname($path);
-    if (preg_match('/\.php$/', $path) && is_file(__DIR__ . $path)) {
+    if (str_ends_with($path, '.php') && is_file(__DIR__ . $path)) {
       // Discovered that the path contains an existing PHP file. Use that as the
       // script to include.
       $script = ltrim($path, '/');