# Custom routes return 404 error but correct content with HEAD request

**URL:** <https://forum.getkirby.com/t/custom-routes-return-404-error-but-correct-content-with-head-request/8343>\
**Category:** Questions\
**Tags:** v2\
**Created:** [August 25, 2017, 12:21pm UTC](https://forum.getkirby.com/t/custom-routes-return-404-error-but-correct-content-with-head-request/8343 "2017-08-25T12:21:52Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 29, 2017, 7:57am UTC](https://forum.getkirby.com/t/custom-routes-return-404-error-but-correct-content-with-head-request/8343/21 "2017-08-29T07:57:34Z")

</div>

Just like in a custom router, either by name of a function or via an anonymous function:

```auto
c:set( 'routes', array(
	array(
		'pattern' => 'archive/(:num)/mail',
		'method' => 'ALL',
        'filter' => function($route) {
           // some checks
          // $route is the route array
         },
		'action' => function( $no ) {
			if ( $issue = page( 'archive/' . $no ) ) {
				return new Response(
					snippet( 'copyMail', array( 'issue' => $issue ), true )
				);
			}
		}
	),
) );

```

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [August 29, 2017, 3:33pm UTC](https://forum.getkirby.com/t/custom-routes-return-404-error-but-correct-content-with-head-request/8343/22 "2017-08-29T15:33:33Z")

</div>

The example by @texnixe should work, but a small addition: Name of a function does not work, it actually needs to be a PHP `Closure` object (anonymous function).

“Global filters” by name are not supported for the Kirby built-in router as there is no way to register global filters in the Kirby router. That’s only possible in custom routers. But of course you can use Closures instead, they work everywhere. 🙂

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:32pm UTC](https://forum.getkirby.com/t/custom-routes-return-404-error-but-correct-content-with-head-request/8343/23 "2025-02-06T17:32:14Z")

</div>

Archived on February 6, 2025, 5:32pm UTC



[Previous page](https://forum.getkirby.com/t/custom-routes-return-404-error-but-correct-content-with-head-request/8343.md?page=1)
