Routes and trailing slash

It seems that Google always shows a trailing slash in the SERPs.


And if I omit the blog folder using routes:

c::set('routes', array(

        'pattern' => '(:any)',
        'action'  => function($uid) {

          $page = page($uid);

          if(!$page) $page = page('blog/' . $uid);
          if(!$page) $page = site()->errorPage();

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


        'pattern' => 'blog/(:any)',
        'action'  => function($uid) {


Then, the blog subpages URLs with a trailing slash doesn’t work. And all the visits from Google are 404 errors.

Is it possible to fix it changing the above code?

I think the main problem here is that your pages are available with and without slash, which ideally shouldn’t be the case. But rather, one should redirect to the other.

You can change or pattern like this:

'pattern' => '(:any)/',

Then it will work with the slash but not without. Or you have to make it optional.

But I’d suggest to decide for one and redirect everything else in your server config or .htaccess.

OK, I removed the trailing slash following this setup:

And now it works fine.