Hey,
is it possible to change the file urls on an existing Kirby website?
Actually it should look like this:
mysite. de/media/pages/PAGENAME/FILENAME
But it would be best like this:
mysite. de/media/FILENAME
I tested a solution here from the forum.
Hey everyone,
there are a bunch of reasons, why we went for this solution based on feedback from many users during v2.
In v2, direct URLs to files always included the sorting number of folders. Whenever you changed the sorting of a page the URL to all its files would break. This is less than ideal for SEO and consistent URLs in general. With the new media API you always get the same URL no matter how the pages are sorted. URLs to files only change when the file itself is being modified.
In v2…
<?php
Kirby::plugin('yourname/old-file-urls', [
'components' => [
'file::url' => function (Kirby $kirby, $file) {
return $kirby->url() . '/content/' . $file->parent()->diruri() . '/' . $file->filename();
},
]
]);
But when I use the plugin, no files are displayed at all.
The URL to images or PDF files is as expected but a 404 error occurs.
Thank you for your help
The plugin’s purpose is to serve files directly from the content folder, which only works for original files but not if you are using thumbs.
You cannot change the path inside the media folder, at least not without creating new file models (and your suggested patterns wouldn’t work if for example, different pages had different files with the same filename).
Thanks for the quick feedback.
So there no way to generate file urls like this:
mysite. de/media/pages/PAGENAME/FILENAME
No, in fact, the media route wouldn’t find the image with such a path.
As I said, you can serve images directly from content instead of the media folder but you cannot influence the media path.
Is there another way to bypass file paths like
/media/pages/home/1d26457bb7-1646054193/filename ?
May I ask what you have in mind for not using the hashed URLs?