BookStackApp / BookStack

A platform to create documentation/wiki content built with PHP & Laravel
https://www.bookstackapp.com/
MIT License
15.12k stars 1.89k forks source link

XAMPP/Apache Subdirectory config not working for homepage #4565

Closed 13robin37 closed 1 year ago

13robin37 commented 1 year ago

Attempted Debugging

Searched GitHub Issues

Describe the Scenario

Sadly I am unable to get the subdirectory config for the homepage to work. BookStack works just fine in all aspects except the homepage which isn't rendered properly (error 404).

When I try to access subpages, books, settings, etc. everything is working as expected. When I try to access https://domain/bookstack it displays "page" not found. When I access https://domain/bookstack/index.php directly the desired homepage is displayed. I've played with the homepage settings under customization without any effect (displaying shelves, custom page, books as the homepage).

APP_URL is set to https://domain/bookstack

Current subdir config within the httpd-ssl.conf (from https://www.bookstackapp.com/docs/admin/subdirectory-setup/):

# BookStack Configuration
    Alias "/bookstack" "D:/xampp/webdir/bookstack/public"
    <Directory "D:/xampp/webdir/bookstack/public">
        Options FollowSymlinks
        AllowOverride none
        Require all granted

        RewriteEngine On
        # Redirect Trailing Slashes If Not A Folder...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)/$ /$1 [L,R=301]

        # Handle Front Controller...
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
    </Directory>

    <Directory "D:/xampp/webdir/bookstack/">
        AllowOverride None
        Require all denied
    </Directory>
    # End BookStack Configuration

I have other applications under D:/xampp/htdocs/ so I moved it to another path to avoid some mixup with .htaccess directives.

Current .htaccess under D:/xampp/webdir/bookstack/public (even tested adding a RewriteRule there, otherwise stock):

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On
    #Subdirectory Test
    #RewriteBase /bookstack

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Tested with APP_DEBUG=true as well but BookStack doesn't throw any errors so I think this is based on some config error on my side. Other hosted apps work just fine, I even run other apps in Directories which don't have any issues. Any idea?

Exact BookStack Version

v23.08.2

Log Content

access.log: "GET /bookstack/ HTTP/2.0" 404 7372

error.log with LogLevel alert rewrite:trace6:

[perdir D:/xampp/webdir/bookstack/public/] strip per-dir prefix: D:/xampp/webdir/bookstack/public/ -> , referer: https://domain/bookstack/
[perdir D:/xampp/webdir/bookstack/public/] applying pattern '^(.*)/$' to uri '', referer: https://domain/bookstack/
[perdir D:/xampp/webdir/bookstack/public/] strip per-dir prefix: D:/xampp/webdir/bookstack/public/ -> , referer: https://domain/bookstack/
[perdir D:/xampp/webdir/bookstack/public/] applying pattern '^' to uri '', referer: https://domain/bookstack/
[perdir D:/xampp/webdir/bookstack/public/] RewriteCond: input='D:/xampp/webdir/bookstack/public/' pattern='!-d' => not-matched, referer: https://domain/bookstack/
[perdir D:/xampp/webdir/bookstack/public/] pass through D:/xampp/webdir/bookstack/public/, referer: https://domain/bookstack/
[perdir D:/xampp/webdir/bookstack/public/] strip per-dir prefix: D:/xampp/webdir/bookstack/public/index.php -> index.php, referer: https://domain/bookstack/
[perdir D:/xampp/webdir/bookstack/public/] applying pattern '^' to uri 'index.php', referer: https://domain/bookstack/
[perdir D:/xampp/webdir/bookstack/public/] RewriteCond: input='D:/xampp/webdir/bookstack/public/index.php' pattern='!-d' => matched, referer: https://domain/bookstack/
[perdir D:/xampp/webdir/bookstack/public/] RewriteCond: input='D:/xampp/webdir/bookstack/public/index.php' pattern='!-f' => not-matched, referer: https://domain/bookstack/
[perdir D:/xampp/webdir/bookstack/public/] pass through D:/xampp/webdir/bookstack/public/index.php, referer: https://domain/bookstack/

Hosting Environment

Windows with XAMPP. Apache/2.4.56 (Win64) OpenSSL/1.1.1t PHP/8.1.17

ssddanbrown commented 1 year ago

Hi @13robin37, Just tested subdirectory usage on a Windows 10 VM and XAMPP, and all worked fine and as expected.

Full VirtualHost Config Used

```apache ServerName bs.test DocumentRoot "C:/xampp/htdocs/static" # BookStack Configuration Alias "/bookstack" "C:/xampp/webdir/bookstack/public" Options FollowSymlinks AllowOverride None Require all granted RewriteEngine On # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] AllowOverride None Require all denied # End BookStack Configuration ErrorLog error.log CustomLog access.log combined ```

I thought maybe your issue could be the trailing slash on the second directory block, but I wasn't able to replicate your issue via adding that to my config.

13robin37 commented 1 year ago

Yea, basically same config as I have used.

Regarding config block, I have multiple aliases under that same domain which all work fine. No folders under xampp/htdocs as well.

As I plan to migrate this to a container environment in the near future anyway, that problem should be solved then.

For now I've set Redirectmatch 301 ^/bookstack/$ https://domain/bookstack/index.php to fix this the dirty way. Let's close this for now, most likely an issue with the vhost config at some point but I don't want to waste your time on that. Thank you for your help!