I have a site that is in the testing phase, so it connects not to the real data but to a local copy of a database.
My customer needs now a fast link to retrieve some urgent and important pdf reports, so I need to set up another version of the site that links to the "real data".
I can create two environments ("local" and "real") with different database connections, and I would like to give the opportunity to select the environment via the URL (I know it's not pretty from a security point of view, but let's take this for granted).
So I would like to use:
my.ip.address/mysite
to use the test db
my.ip.address/mysite/real
to use the real db, redirecting to the URLs without the "real folders".
F.ex.: /mysite/real/admin
should redirect to /mysite/admin
but selecting the "real" environment on Laravel 4.
is it possible to pattern-match also folders in Laravel 4 or is it possible only for domains? In other words, does this work?
$env = $app->detectEnvironment(array(
'test' => array('*/mysite/*'),
'real' => array('*/mysite/real/*'),
));
If so, I just can't figure out how to write the .htaccess rule, I've tried
RewriteRule ^/real(.*)$ $1
But it won't work.
I'm not sure if Laravel's internal environment handling works with folders, but it definitely works with subdomains. You could choose to setup your app using two Apache vhosts, one named test.example.local
, one named real.example.local
and then set the environment option in Laravel like this:
$env = $app->detectEnvironment(array(
'test' => array('test.example.local'),
'real' => array('real.example.local'),
));
There's a second option using .htaccess: You could set this in your .htaccess...
SetEnv LARAVEL_ENVIRONMENT test
SetEnv LARAVEL_ENVIRONMENT real
Then you could set your environment in Laravel like so:
$env = $app->detectEnvironment(function()
{
return $_SERVER['LARAVEL_ENVIRONMENT'];
});
Add the below code in bootstrap/start.php
putenv('LARAVEL_ENV=production');
$env = $app->detectEnvironment( function()
{
return getenv('LARAVEL_ENV') ?: 'staging';
});
Note: If there is "detectEnvironment" already mentioned in this file replace it.
Keep in mind, this approach would make every environment production. To overcome this set the environment variable in .htaccess file
Syntax: SetEnv VAR_NAME "var_value"
SetEnv LARAVEL_ENV production
Hope this is helpful.