Fix Broken Images after Migrating your BookStack App to a New Domain
February 6, 2019

Fix Broken Images after Migrating your BookStack App to a New Domain

Just a quick post on how to migrate your Bookstack App to a new server/domain/url.

There is some official documentation on how to backup & restore your bookstack instance. The method is simple: copy over your directory and your database to the new server and update your configuration (/var/www/BookStack/config/app.config). Unfortunately it doesn't dive into what to do if you are changing your url. Perhaps in the future there will be an official method to do this, but for now, it seems that after moving your BookStack you will end up with broken images. This is because locally uploaded images are stored as hardcoded links with absolute URL-s in the page content. But this can be fixed easily enough in the database! Just run something along these lines (make sure to make a backup of your tables first!):

UPDATE pages
SET 	html =	
		REPLACE(
			REPLACE(
				html, 'http://YOUR.OLD.URL', 'https://YOUR.NEW.URL'), 
				'https://YOUR.OLD.URL', 'YOUR.NEW.URL');
UPDATE images
SET 	url =	
		REPLACE(
			REPLACE(
				url, 'http://YOUR.OLD.URL', 'https://YOUR.NEW.URL'), 
				'https://YOUR.OLD.URL', 'YOUR.NEW.URL');

I may well be missing something - let me know in the comments section below!

UPDATE 2019-02-06: there's an issue requesting an admin feature to help with the above on BookStack's git page

UPDATE 2020-10-16:

For those stumbling upon this feature request: The command is implemented exactly as proposed and documented on https://www.bookstackapp.com/docs/admin/commands/. (crainsaw)
Fix Broken Images after Migrating your BookStack App to a New Domain
Share this