Welcome Guest, Not a member yet? Register   Sign In
Problems with .htaccess and environments?
#1

Here is my .htaccess file:

Code:
RewriteEngine On
SetEnvIf Host www.mysite.ca$ CI_ENV=production
SetEnvIf Host test.mysite.ca$ CI_ENV=testing
SetEnvIf Host localhost$ CI_ENV=development

RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

And this is what I have in index.php

Code:
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
        break;

        case 'testing':
        case 'production':
            error_reporting(0);
        break;

        default:
            exit('The application environment is not set correctly.');
    }
}

So Im doing something wrong, because I uploaded the application to www.mysite.ca and it keeps defaulting to development, not production.
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply
#2

(04-30-2015, 08:27 AM)lexxtoronto Wrote: Here is my .htaccess file:



Code:
RewriteEngine On
SetEnvIf Host www.mysite.ca$ CI_ENV=production
SetEnvIf Host test.mysite.ca$ CI_ENV=testing
SetEnvIf Host localhost$ CI_ENV=development

RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

First, the "RewriteEngine On" should be after your SetEnvIf statements. It probably makes no difference here, but it's best to keep the Rewrite stuff together.

Second, you should probably use SetEnvIfNoCase instead of SetEnvIf, since you have little to no control over the case of the Host variable in most cases.

Third, try escaping the dots in your host names (so \. instead of .).

In the worst case, you may need an IfModule statement:

Code:
<IfModule mod_setenvif.c>
   SetEnvIfNoCase Host www\.mysite\.ca$ CI_ENV=production

   SetEnvIfNoCase Host test\.mysite\.ca$ CI_ENV=testing
   SetEnvIfNoCase Host localhost$ CI_ENV=development
</IfModule>
<IfModule !mod_setenvif.c>
    SetEnv CI_ENV=development
</IfModule>
<IfModule mod_rewrite.c>
   RewriteEngine On

   RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
Reply
#3

Just a note that if you are doing anything using the CLI, those ENV vars (all $_SERVER vars) won't be present since it's not running through the webserver.
Reply
#4

CLI command line interface? Im just editing these files fia ftp client. @mwhitney, @CroNiX thank you for your time! But its not working. I'll just set it manually
Do the one thing you think you cannot do. Fail at it. Try again. Do better the second time. The only people who never tumble are those who never mount the high wire.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB