From bce724ca7663b4f0888ff30c0021a0ee7e356958 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 3 Oct 2017 15:43:14 +0100 Subject: [PATCH 1/2] Use index.php for serving content Removes main.php reliance. Paves the way for serving SilverStripe from a public/ subfolder in the base path. This requires an index.php file in the webroot, since you can't set a RewriteRule to a path outside of the webroot (e.g. "public/.htaccess" pointing to "../vendor/silverstripe/framework/main.php"). --- assets/.htaccess | 2 +- index.php | 67 ++++++++++-------------------------------------- 2 files changed, 14 insertions(+), 55 deletions(-) diff --git a/assets/.htaccess b/assets/.htaccess index 46ac7a5..eebdb1d 100644 --- a/assets/.htaccess +++ b/assets/.htaccess @@ -26,5 +26,5 @@ # Non existant files passed to requesthandler RewriteCond %{REQUEST_URI} ^(.*)$ RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule .* ../vendor/silverstripe/framework/main.php?url=%1 [QSA] + RewriteRule .* ../index.php [QSA] diff --git a/index.php b/index.php index d305318..58cf223 100644 --- a/index.php +++ b/index.php @@ -1,59 +1,18 @@ $snLen && substr($_SERVER['REQUEST_URI'], 0, $snLen + 1) == ($_SERVER['SCRIPT_NAME'] . '/')) { - $url = substr($_SERVER['REQUEST_URI'], $snLen + 1); - $url = strtok($url, '?'); - } else { - $url = $_SERVER['REQUEST_URI']; - if ($url[0] == '/') { - $url = substr($url, 1); - } - $url = strtok($url, '?'); - } - -// Apache will populate the server variables this way -} else { - if ($ruLen > $snLen && substr($_SERVER['REQUEST_URI'], 0, $snLen + 1) == ($_SERVER['SCRIPT_NAME'] . '/')) { - $url = substr($_SERVER['REQUEST_URI'], $snLen + 1); - $url = strtok($url, '?'); - } else { - $url = ""; - } -} - -$_GET['url'] = $_REQUEST['url'] = $url; - -$fileName = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $url; - -// Pass through references to existing files -if ($url && file_exists($fileName)) { - return false; -} - -require_once 'vendor/silverstripe/framework/main.php'; +// Default application +$kernel = new CoreKernel(BASE_PATH); +$app = new HTTPApplication($kernel); +$app->addMiddleware(new ErrorControlChainMiddleware($app)); +$response = $app->handle($request); +$response->output(); From c369cd2358a3eabc25fbf06da53c365a3fd9aceb Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 5 Oct 2017 08:18:51 +0100 Subject: [PATCH 2/2] Move index.php to recipe-core It needs to work with installer-less projects as well --- index.php | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 index.php diff --git a/index.php b/index.php deleted file mode 100644 index 58cf223..0000000 --- a/index.php +++ /dev/null @@ -1,18 +0,0 @@ -addMiddleware(new ErrorControlChainMiddleware($app)); -$response = $app->handle($request); -$response->output();