Bootstrap laravel 来自 public 子文件夹

Bootstrap laravel from public sub-folder

我在 apache 上有一个 Laravel v5.5 运行,我需要通过智能卡证书实现用户验证(使用 apache SSLVerifyClient 要求)。

这意味着我需要一个 public 文件夹,它将要求提供客户证书,我的 public 文件夹结构如下:

/public/
 |- index.php <-- laravel main bootstrap
 |- login/
    |- .htaccess <-- let's apache to ask for client cert only on this folder
    |- index.php <-- secondary bootstrap, that should work as main bootstrap

如何从子文件夹 bootstrap laravel (public/login/index.php),这样它将保持路径和路由与主要 bootstrap (public/index.php )?

我试过

<?php
require_once '../index.php';

<?php
// copy-paste the content from ../index.php and change the paths

define('LARAVEL_START', microtime(true));
require __DIR__.'/../../vendor/autoload.php';
$app = require_once __DIR__.'/../../bootstrap/app.php';

// ...

但它们都处理路由,就好像“/login”是主根“/

这是我目前的工作解决方案。由于单独的 /login 路径的唯一目的是从 $_SERVER 收集证书信息,然后将其传递给适当的 laravel 控制器,我只需要引导 laravel 即可访问正确的会话实例。

// -- file login/index.php

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

// trigger all the middlewares (including SessionStart)
$response = $kernel->handle($request);

// check client verification and store certificate information to session
$request->session()->put([
    'login-card-cert' => $request->server('SSL_CLIENT_CERT'),
    'login-card-user' => $request->server('SSL_CLIENT_S_DN'),
]);
$request->session()->save();

// use away() to send user out of the sub-folder and back to main laravel route
$response = redirect()->away('/do-login/');

// finish up with request (laravel termination)
$response->send();
$kernel->terminate($request, $response);