browser showing to many redirection when connect 'base_url'.
Example, when I enter "www.xxx.com" , then codeigniter showing error!( to many redirection)
but I enter "www.xxx.com/login", showing login controller page! what happen to me..? I want to see default controller. but this doesn't working...
this is my codeigniter config source.
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://" . $_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);
end this is my codeigniter route source.
$route['default_controller'] = 'login';
$route['404_override'] = 'error404';
$route['translate_uri_dashes'] = FALSE;
$route['assets/(:any)'] = 'assets/$1';
end, this is my codeigniter Login controller source.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller
{
private $menu = "login";
function __construct()
{
parent::__construct();
}
function index()
{
$data['menu'] = $this->menu;
$this->load->view('include/header', $data);
$this->load->view('login/login');
$this->load->view('include/footer');
}
function register()
{
$data['menu'] = $this->menu;
$this->load->view('include/header', $data);
$this->load->view('login/register');
$this->load->view('include/footer');
}
}
last this is my .htaccess source.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.php|images|assets|captcha|data|include|uploads|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
I don't understand why default_controller doesn't working! What refers to I do?
$_SERVER['HTTP_HOST']to dynamically assignbase_url()I strongly suggest using the approach documented HERE There are security concerns using$_SERVER['HTTP_HOST']$protocol = (is_https() === TRUE) ? 'https://' : 'http://';then$config['base_url'] = $protocol."example.com".'/';Yes, hard code the domain. See my previous comment as to how/why to be ENVIRONMENT specific.