Kirby routing = 301?

Right, possibly silly question, but as I don’t know I…umm…don’t know, and I’m thinking at least one of you probably do know:

If I were to implement the routing as described on http://getkirby.com/docs/advanced/routing, would that create “301 redirects”? The client used to have a Shopify site with a blog, where the blog posts lived in a specific folder structure. With Kirby that folder structure becomes a lot simpler and more straight-forward, so I’ve been asked to do “301 redirects” from old content URL’s to the new URL’s. Will routing do it? Or do I need to sort this on nginx (web server) or haproxy (load balancer) level?

If the route action is something with

return site()->visit($page);

there is actually no redirect at all.
A route with

go($somewhere)

does a 302 redirect, because this is what the go() function does as default.

I had some problems with doing a 301 redirect with the go() functions so i simply used:

header::redirect($some_url, 301);

I hope this will help.

2 Likes

Ah, thanks @jbeyerstedt, that looks simple/succinct enough.
So, just to be completely clear: would that header::redirect($some_url, 301); happen as the action => of the routing or should that header line be implemented elsewhere?

Would something like this (just throwing it in here by copy/paste/improvise) do it:

c::set('routes', array(
 array(
    'pattern' => 'my/old/url',
    'action'  => function() {

      header::redirect('my/new/url', 301);

     }
  )
));

It should work with your code, but I have not tested it. I use the header::redirect method only in my templates to re-route my onepager sections to the parent page.

Just for the sake of completeness: thanks again @jbeyerstedt, it works fine and the SEO expert is now happy(-ish…not sure he’ll ever be truly happy…). :smile:

1 Like