BERARM
BERARM

Reputation: 247

Lumen GET Requests Return 404 Error

define('ROUTE_BASE', 'lumen/public');

$app->get(ROUTE_BASE . '/', function () use ($app) {
    return $app->welcome();
});

$app->get(ROUTE_BASE . '/test', function () use ($app) {
    return 'test data : 123 abc !';
});

When I access 'localhost/lumen/public/' I can see the 'lumen welcome page'.

But if I try to access 'localhost/lumen/public/test', I receive the following error.

Error: its not found(404).

Upvotes: 1

Views: 4407

Answers (2)

user3562918
user3562918

Reputation: 76

your lumen project must be put in webroot of your localhost,domain or virtual host not in subfolder of your webroot without edit your .htaccess. for access your project in browser : http://lumen.laravel.dev not http://lumen.laravel.dev/public/

I hope this help. sorry for my English :)

Upvotes: 0

Jeemusu
Jeemusu

Reputation: 10533

Laravel expects the public directory to be the webroot of your domain. As this is not true in your case, you will need to make some alterations to your .htaccess.

Options +FollowSymLinks
RewriteEngine On
RewriteBase /lumen/public

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

Also worth noting that instead of using a constant, you can use route groups to achieve the same functionality in your routes.php.

$app->group(['prefix' => 'lumen/public'], function ($app) {
    $app->get('/', function ()  {
        //welcome
    });

    $app->get('test', function ()  {
        return 'test data : 123 abc !';
    });
});

Upvotes: 1

Related Questions