Ugly File Links & 404 Issues After Deployment

Hi,

I created a field of type “blocks” and am using it without any modifications to the default blocks. Within this field, I use the default “list” block to create a list of links pointing to files.

The output is generated via <?= $page->sideblock()->toBlocks() ?>, but the resulting links look like this:
<a href="/@/file/BHOSrVVmFd6UyOjv" target="_blank">Foo</a>

This is quite ugly—especially from an SEO perspective. Is there a way to change these links to permalinks so that they generate a more user-friendly URL?

Another issue I’m facing is that after pushing new code to the live system (without modifying the content folder), the file links stop working and result in a “not found” error. However, if I re-link the file in the panel and save the page again, the link works as expected.

Any idea what might be causing this behavior?

Thanks in advance!

Those ugly file links are, in fact, permalinks.

You can get rid of them by overwriting the snippets for the relevant block types (copy the original (which you can find here: Blocks | Kirby CMS) to site/snippets/blocks with the same file name, e.g. list.php.

Then call the permalinksToUrls() method on the text field.

Original

<?php /** @var \Kirby\Cms\Block $block */ ?>
<?= $block->text();

After

<?php /** @var \Kirby\Cms\Block $block */ ?>
<?= $block->text()->permalinksToUrls();

As regards the error, do not deploy the media or /site/cache folders to your server.

1 Like