Images and "internal" links should not be referred by the (current) Bookstack-URL #996

Closed
opened 2026-02-04 23:20:54 +03:00 by OVERLORD · 5 comments
Owner

Originally created by @ghost on GitHub (Jan 17, 2019).

Hi,

today i found one thing that bothers me... I'll try to make it as short as possible:

Back in the day when I initially set up BookStack I was running it on a custom Port, so the BookStack-URL was something like "https://your.imagination.here:12345".

I created a lot of books and pages, some of them had 40-50 pictures (it was documentation for some server-installation-procedure) plus text in them.

As time went by and I grew confident in the project, I changed the custom port to a standard :443, which means that from now on I could reach BookStack via "https://your.imagination.here".

Today I wanted to review some of my older books / pages and found all the images "missing".

I found out that BookStack tried loading them from the public URL (including the custom port I had to use back then) back in the day when I created the page.
https://your.imagination.here:12345/uploads/images/gallery/2018-10-Oct/scaled-840-0/KvRsGNZDj6T6zCEY-image-1538991146823.png

After testing quiet a bit I found that also "internal" Links (via "Insert Link" and manual page-selection from existing pages) are stored that way, which means they are not working any more...

This seems to be a bad idea, as it would mean that you may never ever change the address under which your BookStack-Instance is being hosted, as it vould make all images and internal links invalid.

So, if today I would host my instance on "bookstack.company.old.name.tld" and tomorrow they change their name so I would have to migrate it to "bookstack.company.new.name.tld" it would show the same problems that I mentioned above...

Any chance someone can come up with an idea on how to link images / links in a form that does not require the "public visible" URL for them to load but use some "internal reference" that is stored in the database and stays the same independent from the URL you use to access the app?

So, something like

  • upload a picture
  • store the file on the servers file system
  • create a unique id, link this one to the filename and store these values in the database
  • when inserting the picture into a page, embed the unique id instead of "hard-linking" the image via the public used url
  • make some PHP script, which when serving the page "on the fly" replaces the "unique id" with the image stored in the folder by looking up the file-system-location of the image using the unique id that is stored in the database...

something like this would be really nice to make BookStack as future-proof as possible, as right now I'm concerned about what happesn if you have created 50 book, 300 pages or whatever, everything perfectly set up and then change your domain / URL. it would all be for nothing, wouldn't it?

edit: alternatively it would be sufficient to have some kind of php artisan command that would just change all (old) strings to the new one...

Originally created by @ghost on GitHub (Jan 17, 2019). Hi, today i found one thing that bothers me... I'll try to make it as short as possible: Back in the day when I initially set up BookStack I was running it on a custom Port, so the BookStack-URL was something like "https://your.imagination.here:12345". I created a lot of books and pages, some of them had 40-50 pictures (it was documentation for some server-installation-procedure) plus text in them. As time went by and I grew confident in the project, I changed the custom port to a standard :443, which means that from now on I could reach BookStack via "https://your.imagination.here". Today I wanted to review some of my older books / pages and found all the images "missing". I found out that BookStack tried loading them from the public URL (including the custom port I had to use back then) back in the day when I created the page. https://your.imagination.here:12345/uploads/images/gallery/2018-10-Oct/scaled-840-0/KvRsGNZDj6T6zCEY-image-1538991146823.png After testing quiet a bit I found that also "internal" Links (via "Insert Link" and manual page-selection from existing pages) are stored that way, which means they are not working any more... This seems to be a bad idea, as it would mean that you may never ever change the address under which your BookStack-Instance is being hosted, as it vould make all images and internal links invalid. So, if today I would host my instance on "bookstack.company.old.name.tld" and tomorrow they change their name so I would have to migrate it to "bookstack.company.new.name.tld" it would show the same problems that I mentioned above... Any chance someone can come up with an idea on how to link images / links in a form that does not require the "public visible" URL for them to load but use some "internal reference" that is stored in the database and stays the same independent from the URL you use to access the app? So, something like - upload a picture - store the file on the servers file system - create a unique id, link this one to the filename and store these values in the database - when inserting the picture into a page, embed the unique id instead of "hard-linking" the image via the public used url - make some PHP script, which when serving the page "on the fly" replaces the "unique id" with the image stored in the folder by looking up the file-system-location of the image using the unique id that is stored in the database... something like this would be really nice to make BookStack as future-proof as possible, as right now I'm concerned about what happesn if you have created 50 book, 300 pages or whatever, everything perfectly set up and then change your domain / URL. it would all be for nothing, wouldn't it? edit: alternatively it would be sufficient to have some kind of php artisan command that would just change all (old) strings to the new one...
Author
Owner

@ssddanbrown commented on GitHub (Jan 17, 2019):

Hi @CliffyPrime, Thanks for the suggestion.

This issue is effectively a duplicate of #1137 and #732 so I will therefore be closing this.

From a technical point of view standardising on absolute URLS (as are currently in BookStack) is easier and requires less conditional logic although, yes, they are less flexible.

I’ve been careful not to store anything in the database in a way that would cause significant isssues when simply doing find/replace operations across the database so that always remains an option.

alternatively it would be sufficient to have some kind of php artisan command that would just change all (old) strings to the new one...

That’s a good idea. I’m sure many admins would be happy to have a helper for this operation. Feel free to open a new issue for that.

@ssddanbrown commented on GitHub (Jan 17, 2019): Hi @CliffyPrime, Thanks for the suggestion. This issue is effectively a duplicate of #1137 and #732 so I will therefore be closing this. From a technical point of view standardising on absolute URLS (as are currently in BookStack) is easier and requires less conditional logic although, yes, they are less flexible. I’ve been careful not to store anything in the database in a way that would cause significant isssues when simply doing find/replace operations across the database so that always remains an option. > alternatively it would be sufficient to have some kind of php artisan command that would just change all (old) strings to the new one... That’s a good idea. I’m sure many admins would be happy to have a helper for this operation. Feel free to open a new issue for that.
Author
Owner

@ghost commented on GitHub (Jan 17, 2019):

thanks for your reply and sorry for me not finding the other issues.

even before you replied I got the same idea of replacing the URLs directly myself.

as I'm not a practiced SQL-guy I was pretty happy to have found a (seemingly, not sure for the long term) solution by:
use bookstackdbnamehere
show tables;
show columns from images;
update images set url = replace(url, ":16938/", "/");
update pages set html = replace(html, ":16938/", "/");

as I said, I'm really not into SQL so I have no clue how to easily find out in which tables and columns the URLs might be stored...
the table images was pretty straight forward, as it contains the column url.
the table pages has a lot of columns and the one called html (of course) contains the html, so replacing the strings there seems to have fixed the problems.
I just wonder: are there more places for me to look for and change these strings?

thank you so much for your work on this project! 👍

@ghost commented on GitHub (Jan 17, 2019): thanks for your reply and sorry for me not finding the other issues. even before you replied I got the same idea of replacing the URLs directly myself. as I'm not a practiced SQL-guy I was pretty happy to have found a (seemingly, not sure for the long term) solution by: use bookstackdbnamehere show tables; show columns from images; update images set url = replace(url, ":16938/", "/"); update pages set html = replace(html, ":16938/", "/"); as I said, I'm really not into SQL so I have no clue how to easily find out in which tables and columns the URLs might be stored... the table images was pretty straight forward, as it contains the column url. the table pages has a lot of columns and the one called html (of course) contains the html, so replacing the strings there seems to have fixed the problems. I just wonder: are there more places for me to look for and change these strings? thank you so much for your work on this project! :+1:
Author
Owner

@ssddanbrown commented on GitHub (Jan 18, 2019):

No problem @CliffyPrime.

Just an advisory to anyone coming across this in the future, Please remember to backup your database before executing any commands to transform URL's.

@CliffyPrime Here's the other tables + columns you might want to update:

  • page_revisions table, html column - Revision history of pages and also storage of in-progress drafts.
  • settings table, value column - Some of the settings hold URL's such as the logo setting.
@ssddanbrown commented on GitHub (Jan 18, 2019): No problem @CliffyPrime. Just an advisory to anyone coming across this in the future, Please remember to backup your database before executing any commands to transform URL's. @CliffyPrime Here's the other tables + columns you might want to update: * `page_revisions` table, `html` column - Revision history of pages and also storage of in-progress drafts. * `settings` table, `value` column - Some of the settings hold URL's such as the logo setting.
Author
Owner

@ghost commented on GitHub (Jan 18, 2019):

Thank you! :)

@ghost commented on GitHub (Jan 18, 2019): Thank you! :)
Author
Owner

@comnam90 commented on GitHub (Mar 13, 2019):

Looping back to this, I'm currently having huge issues with this because I need to be able to reach my Bookstack instance on 2 separate URLs. One internal URL, and one external URL.
For the most part, leaving APP_URL blank, allows this to work. But things like images and such seem to fall over.
As per the PR #1275 I think dynamic links are needed as well as images should be relative not absolute, as it causes me massive pains.

@comnam90 commented on GitHub (Mar 13, 2019): Looping back to this, I'm currently having huge issues with this because I need to be able to reach my Bookstack instance on 2 separate URLs. One internal URL, and one external URL. For the most part, leaving APP_URL blank, allows this to work. But things like images and such seem to fall over. As per the PR #1275 I think dynamic links are needed as well as images should be relative not absolute, as it causes me massive pains.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#996