I would like to drive my environment (dev, prod) by URL
myuser.ENV.domain (eg : foo.dev.test.com or foo.prod.test.com)
So I decide to do some changes in .htaccess file
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_NAME} mydevserver.priv?$
RewriteCond %{HTTP_HOST} ^(.+)\.(.+)\.(mydevserver.priv)?(:80)?$
RewriteRule .* - [E=SF_USER:%1,E=SF_ENV:%2,E=SF_SERVER:%3,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>
Next, I do some changes in app.php
<?php
ini_set('memory_limit', '256M');
umask(0000);
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
$env = filter_input(INPUT_SERVER, 'SF_ENV') ?: $_SERVER['SF_ENV'];
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__ . '/../app/autoload.php';
if ('dev' === $env) {
$debug = true;
Debug::enable();
} elseif ('prod' === $env) {
include_once __DIR__ . '/../var/bootstrap.php.cache';
$debug = false;
} else {
throw new \Exception('Environment Not handled');
}
$kernel = new AppKernel($env, $debug);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
When I go on the prod URL, I have the default success page of Symfony 3, without debug toolbar.
When I go on the dev URL, I have the default success page but I don't have the debug toolbar. There is a 404 error about _wdt & _profiler routes.
But, If I go on the file app_dev.php, I have the debug tool bar.
I probably miss a little thing but I can't figure out.
I did a fast test renaming app.php into index.php and remove the DirectoryIndex but it changes nothing.
If I user var_dump on my $env var, it gets the good env from environment variable SF_ENV.
Can someone help me ?