CGI url routing – no route

driici
Member | 5
+
0
-

Hello,
I am not really sure if it is bug or not or mine error in CGI config :-|

My development config is XAMPP with PHP5 and PHP7 as CGI – it is configured to sit at specific directories and via browser as http://localhost for PHP5 and http://localhost7 for PHP7. Some apps are run from directories (http://localhost7/dndInspector), some have its own vhost (http://dndInspector.local).

I have problems with Nette\Application\BadRequestException #404 – No route for HTTP request thrown every times I try to reach some url when app is ran from within directory (http://localhost7/dndInspector)

But if I configure vhost as http://dndInspector.local it works.

I have tried to dig deep into Nette`s core and suspecting folloving code causes mine issue.

RequestFactory::createHttpRequest

<?php
		$lpath = strtolower($path);
		$script = isset($_SERVER['SCRIPT_NAME']) ? strtolower($_SERVER['SCRIPT_NAME']) : '';
		if ($lpath !== $script) {
			$max = min(strlen($lpath), strlen($script));
			for ($i = 0; $i < $max && $lpath[$i] === $script[$i]; $i++);
			$path = $i ? substr($path, 0, strrpos($path, '/', $i - strlen($path) - 1) + 1) : '/';
		}
?>

I am wondering about this for cycle as in my opinion it will be run exactly one times in all cases.

I have dumped variables just behind this code snipped and values looks like this:
$lpath ⇒ “/dndinspector/www/”
$script ⇒ “http://localhost7/dndinspector/www/”
$path ⇒ “/”
Main problem I see is in $path, it should contain same value as $lpath, but I am really not sure…

With mine hotfix app works at url http://localhost7/dndInspector, but I am unsure if it breaks anything else.

<?php
for ($i = 0; $i < $max && $lpath[$i] === $script[$i]; $i++){
	$path = $i ? substr($path, 0, strrpos($path, '/', $i - strlen($path) - 1) + 1) : '/';
}
?>

Last edited by driici (2017-04-18 12:20)