Login redirect issue #844

Closed
opened 2026-02-04 22:27:44 +03:00 by OVERLORD · 6 comments
Owner

Originally created by @meminens on GitHub (Oct 6, 2018).

Describe the bug
After logging into my account, a redirection occurs to https://xxx.com/BookStack/BookStack. Root is normally https://xxx.com/BookStack. And an error message shows up saying Sorry, The page you were looking for could not be found. But login is successful and there are no other issues.

Steps To Reproduce
See above.

Expected behavior
No redirection should occur.

Screenshots
N/A

Your Configuration (please complete the following information):

  • Exact BookStack Version (Found in settings):
  • PHP Version: 7.2
  • Hosting Method (Nginx/Apache/Docker): Apache

Additional context
Apache configuration:

 Alias /BookStack "/var/www/xxx.com/html/BookStack/public/"
 <Location /BookStack>
     Options +FollowSymLinks
     RewriteEngine On
     # 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]
     # Handle Front Controller...
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^ index.php [L]
 </Location>
Originally created by @meminens on GitHub (Oct 6, 2018). **Describe the bug** After logging into my account, a redirection occurs to https://xxx.com/BookStack/BookStack. Root is normally https://xxx.com/BookStack. And an error message shows up saying `Sorry, The page you were looking for could not be found.` But login is successful and there are no other issues. **Steps To Reproduce** See above. **Expected behavior** No redirection should occur. **Screenshots** N/A **Your Configuration (please complete the following information):** - Exact BookStack Version (Found in settings): - PHP Version: 7.2 - Hosting Method (Nginx/Apache/Docker): Apache **Additional context** Apache configuration: ``` Alias /BookStack "/var/www/xxx.com/html/BookStack/public/" <Location /BookStack> Options +FollowSymLinks RewriteEngine On # 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] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </Location> ```
OVERLORD added the 🐛 Bug🏭 Back-End labels 2026-02-04 22:27:44 +03:00
Author
Owner

@meminens commented on GitHub (Oct 6, 2018):

I can't edit the OP for some reason.

BookStack v0.24.1

@meminens commented on GitHub (Oct 6, 2018): I can't edit the OP for some reason. BookStack v0.24.1
Author
Owner

@ssddanbrown commented on GitHub (Oct 13, 2018):

Hi @bisherbas,
If you are still having this issue, Can you post your full, current configuration? I assume it's changed after following the chain in #1044. Just so I can use the same config to try to replicate the issue.

@ssddanbrown commented on GitHub (Oct 13, 2018): Hi @bisherbas, If you are still having this issue, Can you post your full, current configuration? I assume it's changed after following the chain in #1044. Just so I can use the same config to try to replicate the issue.
Author
Owner

@meminens commented on GitHub (Oct 14, 2018):

bookstack.conf:

 Alias /bookstack "/var/www/bookstack/public/"
 <Directory "/var/www/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 "/var/www/bookstack">
      AllowOverride None
      Require all denied
</Directory>
# End BookStack Configuration

apache.conf:

<Directory />
     Options FollowSymLinks
     AllowOverride None
     Require all denied
 </Directory>

 <Directory /usr/share>
     AllowOverride None
     Require all granted
 </Directory>

 <Directory /var/www/>
     Options FollowSymLinks
     AllowOverride All
     Require all granted
 </Directory>
@meminens commented on GitHub (Oct 14, 2018): ### `bookstack.conf`: ``` Alias /bookstack "/var/www/bookstack/public/" <Directory "/var/www/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 "/var/www/bookstack"> AllowOverride None Require all denied </Directory> # End BookStack Configuration ``` ### `apache.conf`: ``` <Directory /> Options FollowSymLinks AllowOverride None Require all denied </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www/> Options FollowSymLinks AllowOverride All Require all granted </Directory> ```
Author
Owner

@ssddanbrown commented on GitHub (Oct 14, 2018):

Thanks @bisherbas.
Can confirm this is a bug in BookStack's url handling. Have marked to be fixed for next release.

As a temporary workaround you could add the following after your Alias line in your bookstack.conf file:

Redirect temp /bookstack/bookstack http://localhost/bookstack/

Developer Reference

Putting here since in test env right now, This might do it, Needs proper testing:

/**
 * Helper to create url's relative to the applications root path.
 * @param string $path
 * @param bool $forceAppDomain
 * @return string
 */
function baseUrl($path, $forceAppDomain = false)
{
    $isFullUrl = strpos($path, 'http') === 0;
    if ($isFullUrl && !$forceAppDomain) {
        return $path;
    }
    
    $path = trim($path, '/');
    $trimBase = rtrim(config('app.url'), '/');

    // Remove non-specified domain if forced and we have a domain
    if ($isFullUrl && $forceAppDomain) {
        if (strpos($path, $trimBase) === 0) {
            $path = trim(substr($path, strlen($trimBase) - 1));
        }
        $explodedPath = explode('/', $path);
        $path = implode('/', array_splice($explodedPath, 3));
    }

    // Return normal url path if not specified in config
    if (config('app.url') === '') {
        return url($path);
    }

    return $trimBase . '/' . $path;
}
@ssddanbrown commented on GitHub (Oct 14, 2018): Thanks @bisherbas. Can confirm this is a bug in BookStack's url handling. Have marked to be fixed for next release. As a temporary workaround you could add the following after your `Alias` line in your bookstack.conf file: ``` Redirect temp /bookstack/bookstack http://localhost/bookstack/ ``` ## Developer Reference Putting here since in test env right now, This might do it, Needs proper testing: ```php /** * Helper to create url's relative to the applications root path. * @param string $path * @param bool $forceAppDomain * @return string */ function baseUrl($path, $forceAppDomain = false) { $isFullUrl = strpos($path, 'http') === 0; if ($isFullUrl && !$forceAppDomain) { return $path; } $path = trim($path, '/'); $trimBase = rtrim(config('app.url'), '/'); // Remove non-specified domain if forced and we have a domain if ($isFullUrl && $forceAppDomain) { if (strpos($path, $trimBase) === 0) { $path = trim(substr($path, strlen($trimBase) - 1)); } $explodedPath = explode('/', $path); $path = implode('/', array_splice($explodedPath, 3)); } // Return normal url path if not specified in config if (config('app.url') === '') { return url($path); } return $trimBase . '/' . $path; } ```
Author
Owner

@ssddanbrown commented on GitHub (Oct 14, 2018):

Found this is essentially already open under #956 so will therefore close this issue since it's a duplicate.

Thanks again for the info provided to diagnose this.

@ssddanbrown commented on GitHub (Oct 14, 2018): Found this is essentially already open under #956 so will therefore close this issue since it's a duplicate. Thanks again for the info provided to diagnose this.
Author
Owner

@GonzaChocan commented on GitHub (Aug 15, 2019):

I know this issue is closed at 14 Oct 2018 but i was trying to install BookStack in AUGUST 2019 and the same issue was passing to me. There´s no need to point BookStack to the Document Root of your server ! I found that when after follow the admin installation guide(except the point i wrote before) had a duplicate URL of the Home Page at Localhost(or a IP or domain where you install the program)/BookStack/public/Bookstack/public and had a "Page not found error" after login. To solve this issue you only have to go to "BookStack\app\Http\Controllers\Auth\LoginController.php" and in the line 109 more or less (could be other) need to change "$path=session()->pull('url.intended','/');" to "$path=session()->pull(' ','/');"

@GonzaChocan commented on GitHub (Aug 15, 2019): I know this issue is closed at 14 Oct 2018 but i was trying to install BookStack in AUGUST 2019 and the same issue was passing to me. **There´s no need to point BookStack to the Document Root of your server !** I found that when after follow the admin installation guide(except the point i wrote before) had a duplicate URL of the Home Page at Localhost(or a IP or domain where you install the program)/BookStack/public/Bookstack/public and had a "Page not found error" after login. To solve this issue you only have to go to **"BookStack\app\Http\Controllers\Auth\LoginController.php"** and in the line 109 more or less (could be other) need to change "**$path=session()->pull('url.intended','/');**" to "**$path=session()->pull(' ','/');**"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#844