codeigniter htaccess and automatic base_url and database group configuration basic setup Category : Codeigniter | Updated at : 2019-02-15 01:26:50

Codeigniter basic setup  htaccess automatic base_url and database group configuration

File : .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Automatic base_url configuration

File : application/config.php

$https = filter_input(INPUT_SERVER, 'HTTPS');
$config['base_url'] = isset($https) ? "https://" : "http://";
$config['base_url'] .= filter_input(INPUT_SERVER, 'HTTP_HOST')
        . str_replace(basename(filter_input(INPUT_SERVER, 'SCRIPT_NAME')),
                "", filter_input(INPUT_SERVER, 'SCRIPT_NAME'));

Automatic database group configuration

$hostname = filter_input(INPUT_SERVER, 'HTTP_HOST');
if($hostname == 'localhost'){
    $active_group = 'local';
}else{
    $active_group = 'example.com';
}