[Bug Report]: Multiple redirects on starting page if installation is in subfolder #2574

Closed
opened 2026-02-05 04:32:25 +03:00 by OVERLORD · 6 comments
Owner

Originally created by @FastHogi on GitHub (Jan 14, 2022).

Describe the Bug

I'm using bookstack in a docker container and use nginx as my reverse proxy to be able to access bookstack from a subfolder URL mydomain.com/bookstack. If you open the developer tools in a browser and have a closer look at the network requests, you will see multiple redirects with multiple trailing slashes when you try to access the starting page (see screenshot). You can also see the multiple slashes in the address bar of the browser (https://mydomain.com/bookstack///////////////////).

This only happens on the starting page. All other pages do not show this behavor and bookstack is still usable. If you click on the bookmark logo left to the search pane, you will be redirected to the starting page, which will show this behavior again.

I added the subfolder path in my local .env file:
APP_URL=https://mydomain.com/bookstack

My nginx location block looks like this:

location /bookstack {
    # redirect to same location with a trailing slash
    return 301 $scheme://$host$request_uri/;
}
location /bookstack/ {
    proxy_pass http://192.168.1.20:6875/;
}

My docker-compose file for running bookstack in a docker container looks like this:

version: '3'
services:
  bookstack:
    container_name: bookstack
    image: lscr.io/linuxserver/bookstack
    restart: always
    environment:
      PUID: 1000
      PGID: 1000
      APP_URL: https://mydomain.com/bookstack
      DB_HOST: bookstack_db
      DB_USER: bookstack
      DB_PASS: ${PASSWORD_MYSQL_BOOKSTACK}
      DB_DATABASE: bookstack
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /data/bookstack:/config
    networks:
      - CustomNet_Bookstack
    ports:
      - 6875:80
    healthcheck:
      test: wget --spider http://localhost/status || exit 1
      interval: 60s
      timeout: 10s
      retries: 5    
    depends_on:
      bookstack_db:
          condition: service_started
  bookstack_db:
    image: lscr.io/linuxserver/mariadb
    restart: always
    container_name: bookstack_db
    environment:
      PUID: 1000
      PGID: 1000
      MYSQL_ROOT_PASSWORD: ${PASSWORD_MYSQL_ROOT}
      TZ: Europe/Berlin
      MYSQL_DATABASE: bookstack
      MYSQL_USER: bookstack
      MYSQL_PASSWORD: ${PASSWORD_MYSQL_BOOKSTACK}
    volumes:
      - /etc/localtime:/etc/localtime:ro    
      - /data/bookstack:/config
    networks:
      - CustomNet_Bookstack
    healthcheck:
      test: mysqladmin ping --user=root --password=${PASSWORD_MYSQL_ROOT} || exit 1
      interval: 60s
      timeout: 10s
      retries: 5    
networks:
  CustomNet_Bookstack:
    name: CustomNet_Bookstack

Steps to Reproduce

  1. install bookstack from the above docker-compose file in a docker container
  2. add a subfolder location in nginx
  3. open the developer tools on your browser
  4. open the bookstack starting page mydomain.com/bookstack
  5. look at the address bar or on the network tab of the developer tools

Expected Behaviour

No multiple redirects on starting page.

Screenshots or Additional Context

grafik

Exact BookStack Version

v21.12.2

PHP Version

7.4.26

Hosting Environment

Originally created by @FastHogi on GitHub (Jan 14, 2022). ### Describe the Bug I'm using bookstack in a docker container and use nginx as my reverse proxy to be able to access bookstack from a subfolder URL mydomain.com/bookstack. If you open the developer tools in a browser and have a closer look at the network requests, you will see multiple redirects with multiple trailing slashes when you try to access the starting page (see screenshot). You can also see the multiple slashes in the address bar of the browser (https://mydomain.com/bookstack///////////////////). This only happens on the starting page. All other pages do not show this behavor and bookstack is still usable. If you click on the bookmark logo left to the search pane, you will be redirected to the starting page, which will show this behavior again. I added the subfolder path in my local `.env` file: `APP_URL=https://mydomain.com/bookstack` My nginx location block looks like this: ``` location /bookstack { # redirect to same location with a trailing slash return 301 $scheme://$host$request_uri/; } location /bookstack/ { proxy_pass http://192.168.1.20:6875/; } ``` My docker-compose file for running bookstack in a docker container looks like this: ``` version: '3' services: bookstack: container_name: bookstack image: lscr.io/linuxserver/bookstack restart: always environment: PUID: 1000 PGID: 1000 APP_URL: https://mydomain.com/bookstack DB_HOST: bookstack_db DB_USER: bookstack DB_PASS: ${PASSWORD_MYSQL_BOOKSTACK} DB_DATABASE: bookstack volumes: - /etc/localtime:/etc/localtime:ro - /data/bookstack:/config networks: - CustomNet_Bookstack ports: - 6875:80 healthcheck: test: wget --spider http://localhost/status || exit 1 interval: 60s timeout: 10s retries: 5 depends_on: bookstack_db: condition: service_started bookstack_db: image: lscr.io/linuxserver/mariadb restart: always container_name: bookstack_db environment: PUID: 1000 PGID: 1000 MYSQL_ROOT_PASSWORD: ${PASSWORD_MYSQL_ROOT} TZ: Europe/Berlin MYSQL_DATABASE: bookstack MYSQL_USER: bookstack MYSQL_PASSWORD: ${PASSWORD_MYSQL_BOOKSTACK} volumes: - /etc/localtime:/etc/localtime:ro - /data/bookstack:/config networks: - CustomNet_Bookstack healthcheck: test: mysqladmin ping --user=root --password=${PASSWORD_MYSQL_ROOT} || exit 1 interval: 60s timeout: 10s retries: 5 networks: CustomNet_Bookstack: name: CustomNet_Bookstack ``` ### Steps to Reproduce 1. install bookstack from the above docker-compose file in a docker container 2. add a subfolder location in nginx 3. open the developer tools on your browser 4. open the bookstack starting page mydomain.com/bookstack 5. look at the address bar or on the network tab of the developer tools ### Expected Behaviour No multiple redirects on starting page. ### Screenshots or Additional Context ![grafik](https://user-images.githubusercontent.com/41678833/149469083-fc68f5f4-b167-4483-9176-5c9686757b4d.png) ### Exact BookStack Version v21.12.2 ### PHP Version 7.4.26 ### Hosting Environment - Ubuntu Server 21.10 running on a raspberry pi4 (4 GB) - Docker engine 20.10.12 - Latest docker image from [https://hub.docker.com/r/linuxserver/bookstack](https://hub.docker.com/r/linuxserver/bookstack)
OVERLORD added the 🐛 Bug label 2026-02-05 04:32:25 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Jan 14, 2022):

Hi @FastHogi,

What happens after you remove the following block?:

location /bookstack {
    # redirect to same location with a trailing slash
    return 301 $scheme://$host$request_uri/;
}
@ssddanbrown commented on GitHub (Jan 14, 2022): Hi @FastHogi, What happens after you remove the following block?: ```nginx location /bookstack { # redirect to same location with a trailing slash return 301 $scheme://$host$request_uri/; } ```
Author
Owner

@FastHogi commented on GitHub (Jan 14, 2022):

Hi @ssddanbrown,

I already tried that, but is has no effect. There are also some further tiny issues with a subfolder installation, but I think's it's best to raise a seperate issue for them. I will try to create a seperate bug report later, when I have more time. Just briefly, to mark a page as a favorite and to switch the light mode to dark and vica-versa is not working in a subfolder installation. So, maybe it's a routing issue where the APP_URL is not fully considered or something like this.

@FastHogi commented on GitHub (Jan 14, 2022): Hi @ssddanbrown, I already tried that, but is has no effect. There are also some further tiny issues with a subfolder installation, but I think's it's best to raise a seperate issue for them. I will try to create a seperate bug report later, when I have more time. Just briefly, to mark a page as a favorite and to switch the light mode to dark and vica-versa is not working in a subfolder installation. So, maybe it's a routing issue where the APP_URL is not fully considered or something like this.
Author
Owner

@ssddanbrown commented on GitHub (Jan 14, 2022):

Okay. I'm not confident these are issues in the core project though and are probable interlinked to config/setup issues. My development instance currently runs in a sub-path on nginx without issue, albeit not proxies to that docker image but to another local host. My config is pretty much this:

	location /bookstack/ {
	 proxy_pass https://bookstack.local/;
	 proxy_redirect off;
	}

Could try adding the proxy_redirect off; clause to see if it helps.

@ssddanbrown commented on GitHub (Jan 14, 2022): Okay. I'm not confident these are issues in the core project though and are probable interlinked to config/setup issues. My development instance currently runs in a sub-path on nginx without issue, albeit not proxies to that docker image but to another local host. My config is pretty much this: ```nginx location /bookstack/ { proxy_pass https://bookstack.local/; proxy_redirect off; } ``` Could try adding the `proxy_redirect off;` clause to see if it helps.
Author
Owner

@FastHogi commented on GitHub (Jan 14, 2022):

Wait... I doubled checked it and removed the location block with the redirection with a trailing slash. I couldn't see these multiple slashes at the starting page anymore. Maybe I didn't start my nginx container after I made the changes. Sorry, for that. The interessing part is, that I have pretty much the same block for a lot of other locations, where there isn't a problem with adding a trailing slash. Anyway... it seems to fix the issue. Thank you.

But the mentioned issues with setting a favorite and switching the dark/light mode still exists. I tried adding proxy_redirect off; but it made no difference (after a nginx restart). I now have pretty much the same location block like you. The only exception is, that I'm proxy passing from https to a different http port. I see you have an local https URL in your location block. Could it be an security issue like secure cookie or something like that? If I switch the dark/light mode, I will be routed back to mydomain.com without the subfolder path.

@FastHogi commented on GitHub (Jan 14, 2022): Wait... I doubled checked it and removed the location block with the redirection with a trailing slash. I couldn't see these multiple slashes at the starting page anymore. Maybe I didn't start my nginx container after I made the changes. Sorry, for that. The interessing part is, that I have pretty much the same block for a lot of other locations, where there isn't a problem with adding a trailing slash. Anyway... it seems to fix the issue. Thank you. But the mentioned issues with setting a favorite and switching the dark/light mode still exists. I tried adding `proxy_redirect off;` but it made no difference (after a nginx restart). I now have pretty much the same location block like you. The only exception is, that I'm proxy passing from https to a different http port. I see you have an local https URL in your location block. Could it be an security issue like `secure cookie` or something like that? If I switch the dark/light mode, I will be routed back to mydomain.com without the subfolder path.
Author
Owner

@FastHogi commented on GitHub (Jan 14, 2022):

I think I found it by myself. In my nginx SSL settings there is a header added add_header Referrer-Policy "strict-origin" always;. If I remove that, I can switch the dark/light mode and no redirection happens anymore. So, it's not a bookstack bug.

Dan, you can close this issue. Thanks for you feedback and quick response. Keep up the awesome work.

@FastHogi commented on GitHub (Jan 14, 2022): I think I found it by myself. In my nginx SSL settings there is a header added `add_header Referrer-Policy "strict-origin" always;`. If I remove that, I can switch the dark/light mode and no redirection happens anymore. So, it's not a bookstack bug. Dan, you can close this issue. Thanks for you feedback and quick response. Keep up the awesome work.
Author
Owner

@ssddanbrown commented on GitHub (Jan 14, 2022):

No worries, happy to hear you found the solution. Will therefore close this off.

@ssddanbrown commented on GitHub (Jan 14, 2022): No worries, happy to hear you found the solution. Will therefore close this off.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2574