Route template to hash

how do i setup the kirby routing to to redirect the last part of the url on specific template.
http://www.example.com/support/some-topic-with-support-template

for template ‘support-topic’ should be (with a # hash)
http://www.example.com/support#some-topic-with-support-template

but other templates in same folder should not be redirected
http://www.example.com/support/do-not-redirect-me-since-i-have-different-template

ideally it would work on any depth in the folder tree.
http://www.example.com/some-topic-with-support-template
http://www.example.com/support/some-topic-with-support-template
http://www.example.com/blog/archive/some-topic-with-support-template

c::set('routes', array(
  array(
    'pattern' => array('(:any)'),
    'action'  => function() {
      // compare if template is equal to 'support-topic' do that
      // else do nothing
    }
  )
));

Even simpler. In site/templates/support-topic.php:

<?php go($page->parent()->url() . '#' . $page->uid());

will this be a 301 or 302 redirect? or none at all?

The go() helper will use an HTTP 302 redirect.
If you need 301, use the following code:

<?php redirect::send($page->parent()->url() . '#' . $page->uid(), 301);
1 Like

hm. can the kirby router do 301? or do i need to use the htaccess file? i would still be intereseted in how to solve this with the router, too.