Transferring Kirby from one server to another

I’m new to Kirby, trying to assist a client who has it running on WebFaction (which is going offline soon). We’ve moved all of the static files to a new server running Apache/PHP8, etc - everything seems to be working fine after moving over .htaccess, etc.

However, the image URLs seem to have shifted even though the files have remained the same. Not all of them, but some of them have shifted. But browsing the old server and new one and inspecting this element, this part (but only this part) of the URL has changed.

http://mysite.domain.com/openwork/media/pages/for-the-many/gallery/ad51a75e0b-1631147315/LOC_1915-1923_30183v.jpg

I’m sure this is a newbie question, but I couldn’t find anything like this in the forums… Thanks!

The hash changes when the file is modified. My guess is that the file dates changed when you moved the files.

Thanks - I just tried to retain timestamps across the servers, but the hash is still changing. Any other ideas?

One thing I noticed is that the timestamps on the directories changed; but the files kept consistent. Would that cause the hash to change?

Isn’t it advised to empty the media folder and let Kirby create these files again upon request?

Yes, but if the modification date changes (which can happen when transferring files without keeping the dates) the file urls will change.

The media hash is also based on the filesystem root of the file. So if the site is stored at a different location on the new server, all these roots change, so all hashes change.

If you need to preserve the original URLs, you can set this option in config.php to generate a custom salt for the hash:

return [
  'content.salt' => function ($file) {
    $oldRoot = '/var/www/html/content'; // change this

    return str_replace(
      $file->kirby()->root('content'),
      $oldRoot,
      $file->root()
    );
  }
];

So then if we moved the files over from the old server to the new one and retained the root as well as modification dates, then the URLs will not change? That might be easiest for us to do in this case.

I can’t believe I never knew this option existed :scream:

Yes, keeping the modification dates intact plus either the root or using the config option above should do the job.