ElpsySec's avatar

How Does Laravel Route Everything to Index.php?

I'm digging through the framework's source code, trying to learn about the IoC Container and such. It seems that the app is bootstrapped in public/index.php with code like:

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

My question is how does the server know to hit index.php with every request? Am I wrong about this? Is it in the web.config? If so, is web.config an nginx file? Does web.config take care of nginx while htaccess routes for apache?

0 likes
3 replies
d3xt3r's avatar
d3xt3r
Best Answer
Level 29

Short answer, yes, its either web.config(ngnix) or .htaccess(apache) that tells server to route everything(expect where actual file exists) to index.php.

2 likes
willvincent's avatar

Short answer, yes, its either web.config(ngnix) or .htaccess(apache) that tells server to route everything(expect where actual file exists) to index.php.

Uh.. no, that's not accurate.

.htaccess is for apache, that's true. web.config however is not for nginx, that's IIS. nginx does not interpret host config overrides on the fly, they're all configured in the nginx host config file, which is read once at start of the nginx service, and then cached in memory-- that's a small part of why it's so much faster.

d3xt3r's avatar

Hmmm, i agree about me being inaccurate about web.config used by nginx. Zest remains the same, laravel does nothing special to achieve the same.

1 like

Please or to participate in this conversation.