BookStack – Redirect Unauthenticated Users to /books #5234

Closed
opened 2026-02-05 09:50:36 +03:00 by OVERLORD · 1 comment
Owner

Originally created by @247no2 on GitHub (Mar 21, 2025).

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

Hi everyone,

I want to configure BookStack so that unauthenticated users (Guest) are redirected to the books overview (/books) instead of seeing the shelves (/) as the default start page.

I have tried using JavaScript redirection, but my attempts either redirected all users (including logged-in ones) or didn't work at all. Since guests are not logged in, I can't check for a username. I also tried detecting the user role (Viewer) or checking for a specific avatar image (guestlogo.jpg), but neither method was successful.

Is there a way to set a default homepage for guests in BookStack, or a reliable method to detect unauthenticated users?

Thanks for your help!

Exact BookStack Version

v24.12.1

Log Content

No response

Hosting Environment

Ubuntu 22.04.4 LTS
PHP 8.1.2
Apache

Originally created by @247no2 on GitHub (Mar 21, 2025). ### Attempted Debugging - [x] I have read the debugging page ### Searched GitHub Issues - [x] I have searched GitHub for the issue. ### Describe the Scenario Hi everyone, I want to configure BookStack so that unauthenticated users (Guest) are redirected to the books overview (/books) instead of seeing the shelves (/) as the default start page. I have tried using JavaScript redirection, but my attempts either redirected all users (including logged-in ones) or didn't work at all. Since guests are not logged in, I can't check for a username. I also tried detecting the user role (Viewer) or checking for a specific avatar image (guestlogo.jpg), but neither method was successful. Is there a way to set a default homepage for guests in BookStack, or a reliable method to detect unauthenticated users? Thanks for your help! ### Exact BookStack Version v24.12.1 ### Log Content _No response_ ### Hosting Environment Ubuntu 22.04.4 LTS PHP 8.1.2 Apache
OVERLORD added the 🐕 Support label 2026-02-05 09:50:36 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Mar 24, 2025):

Hi @247no2,
Here's a solution using the logical theme system. Follow the getting started part of the linked guidance to get a working functions.php theme file, then the following should work for your scenario:

<?php

use BookStack\Facades\Theme;
use BookStack\Theming\ThemeEvents;
use Illuminate\Http\Request;

// Listen to WEB_MIDDLEWARE_BEFORE so we can check the request when it comes in.
Theme::listen(ThemeEvents::WEB_MIDDLEWARE_BEFORE, function (Request $request) {

    // Redirect to /books if the path matches the homepage
    $isHomepage = trim($request->path(), '/') === '';
    if ($isHomepage && user()->isGuest()) {
        return redirect('/books');
    }

    return null;
});

Note: This is an unofficial customization which could potentially have issues or break on future update.

@ssddanbrown commented on GitHub (Mar 24, 2025): Hi @247no2, Here's a solution using the [logical theme system](https://github.com/BookStackApp/BookStack/blob/development/dev/docs/logical-theme-system.md#logical-theme-system). Follow the getting started part of the linked guidance to get a working `functions.php` theme file, then the following should work for your scenario: ```php <?php use BookStack\Facades\Theme; use BookStack\Theming\ThemeEvents; use Illuminate\Http\Request; // Listen to WEB_MIDDLEWARE_BEFORE so we can check the request when it comes in. Theme::listen(ThemeEvents::WEB_MIDDLEWARE_BEFORE, function (Request $request) { // Redirect to /books if the path matches the homepage $isHomepage = trim($request->path(), '/') === ''; if ($isHomepage && user()->isGuest()) { return redirect('/books'); } return null; }); ``` Note: This is an unofficial customization which could potentially have issues or break on future update.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#5234