Redirect loop after installation | Uri | AdminPlugin

Hey,

I have clean installation from ZIP package. I’m using AMMPS 3.6 on Windows. My instance of Grav is installed in a subdirectory D:/work/tests/test-grav/grav/. I’m running Grav 1.1.12 and Admin Panel 1.2.7.

Issue 1
I’m trying to access fresh installation on http://localhost/work/tests/test-grav/grav/, but the browser says it noticed a redirect loop. Developer Tools on Chrome shows bunch of redirects from http://localhost/work/tests/test-grav/grav/ to http://localhost/work/tests/test-grav/grav and so on…

Solution 1 (but not really)
I managed to notice that the problem starts in Grav\Common\Uri class around line 294:

if ($config->get('system.pages.redirect_trailing_slash', false) && $uri != '/' && Utils::endsWith($uri, '/')) {`
    $grav->redirect(str_replace($this->root, '', rtrim($uri, '/')), 301);`
}

I edited a file /system/config/system.yaml changing redirect_trailing_slash to false which resolved that issue. Unfortunately, there’s another one — redirect loop, but in different place. I also changed errors.displayto 1 and debugger.enabled to true, but nothing shows in /logs/ directory.

Issue 2
After my change in configuration, Grav started to simply redirect from and to http://localhost/work/tests/test-grav/grav/admin. It was just constantly redirecting itself to the same URL.

I managed to find a source of the problem in Grav\Plugin\AdminPlugin around line 125:

if ($user_check == false || count((array)$user_check) == 0) {
    if (!$this->isAdminPath()) {
        $this->grav->redirect($this->admin_route);
    }
    $this->template = 'register';
}

Basically $this->isAdminPath() returns false. I’ve put var_dump inside that function, based on conditional statement:

var_dump(
	$this->uri->route(),
	'==',
	$this->base,
	'||',
	substr($this->uri->route(), 0, strlen($this->base) + 1),
	'==',
	$this->base . '/'
);exit;

which resulted in following output:

D:\work  ests  est-grav\grav\user\plugins\admin\admin.php:788:string '/work/tests/test-grav/grav/admin' (length=32)
D:\work  ests  est-grav\grav\user\plugins\admin\admin.php:788:string '==' (length=2)
D:\work  ests  est-grav\grav\user\plugins\admin\admin.php:788:string '/admin' (length=6)
D:\work  ests  est-grav\grav\user\plugins\admin\admin.php:788:string '||' (length=2)
D:\work  ests  est-grav\grav\user\plugins\admin\admin.php:788:string '/work/' (length=6)
D:\work  ests  est-grav\grav\user\plugins\admin\admin.php:788:string '==' (length=2)
D:\work  ests  est-grav\grav\user\plugins\admin\admin.php:788:string '/admin/' (length=7)

Additionally, I’ve put var_dump at the end of init method inside Grav\Common\Uri class which resulted in following output:

D:\work  ests  est-grav\grav\system\src\Grav\Common\Uri.php:351:
object(Grav\Common\Uri)[65]
  public 'url' => string 'http://localhost/work/tests/test-grav/grav/work/tests/test-grav/grav/admin' (length=74)
  protected 'base' => string 'http://localhost' (length=16)
  protected 'basename' => string 'admin' (length=5)
  protected 'bits' => null
  protected 'content_path' => string 'work/tests/test-grav/grav/admin' (length=31)
  protected 'extension' => null
  protected 'host' => string 'localhost' (length=9)
  protected 'env' => string 'localhost' (length=9)
  protected 'params' => 
    array (size=0)
      empty
  protected 'path' => string '/work/tests/test-grav/grav/admin' (length=32)
  protected 'paths' => 
    array (size=5)
      0 => string 'work' (length=4)
      1 => string 'tests' (length=5)
      2 => string 'test-grav' (length=9)
      3 => string 'grav' (length=4)
      4 => string 'admin' (length=5)
  protected 'scheme' => string 'http://' (length=7)
  protected 'port' => string '80' (length=2)
  protected 'query' => 
    array (size=0)
      empty
  protected 'fragment' => null
  protected 'root' => string 'http://localhost/work/tests/test-grav/grav' (length=42)
  protected 'root_path' => string '/work/tests/test-grav/grav' (length=26)
  protected 'uri' => string '/work/tests/test-grav/grav/admin' (length=32)
  public 'name' => string 'localhost' (length=9)

Pay attention to the Grav\Common\Uri->url field. It’s clearly wrong. I suppose that source of the problem is somewhere in the Uri class.

Thanks for reporting this detailed report of the problem. Just to help find the cause of the problem, can you check if is the same happening on MAMP? https://www.mamp.info/en/downloads/