Search code examples
phproutesapache2lumen

Lumen routing doesn't work


Here is my routing code:

$app->get('/foo', function () {
    return 'Hello World';
});
$app->get('/', function(){
    return 'asd';
});

the problem is that I always get "asd" on the page, even if I visit some random route, which doesn't exist. So if I visit localhost/sadgasgasdgsa I will get 'asd' on the page. I also get 'asd', instant of 'Hello World', when I visit localhost/foo. Any ideas what the problem my be?

Note: This seems like the same question: Lumen routes not working other than '/' route However nobody has answered the question. My server confirmation simple WAMP, php 7, apache2 and mysql. While searching for solution, I added the following .htaccess file:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

However it isn't working EDIT For those who came here with the search engine, I've down-graded the version of lumen, and it started working.


Solution

  • Upgraded from Lumen 5.3 to 5.4 and had the same problem, only '/' route worked.

    Digging in revealed that I had broken the code as the solution for earlier problem in Lumen 5.2 that was fixed according to this popular answer.

    Problem was in bootstrap/index.php:

    $app->run($app->make('request'))

    Input parameter $app->make('request'), which was added as the fix of Laravel 5.2 problem, made an empty request object that was missing actual request data. That's why default '/' kicked in, request object did not have any path info.

    I looked the original public/index.php file in github and $app->run() did not have any parameter. When I deleted the $app->make('request') input parameter the app started working.