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?
I'm really sorry. All problem start at 'hooks'! I recommended "Auth"hook. But, when I changing my domain, I'm not edit my hook. When edit domain, everything works well.! Thanks for your comment. It's really advise to me.
here is my 'Auth.php' < hook!
<?php
class Auth {
function check_login() {
$CI =& get_instance();
isset($CI->session) OR $CI->load->library('session');
$CI->session->has_userdata('user_name') OR
$CI->session->set_userdata('user_name', 'guest');
$username = $CI->session->userdata('user_name');
if(!(strpos(current_url(), "authentication")) &&
!(current_url() === "http://my_domain.com") &&
!(current_url() === "http://my_domain.com/"))
{
if($username==='guest' &&
!(isset($CI->allowed_method) &&
in_array($CI->router->method, $CI->allowed_method)))
{
redirect("/");
}
}
}
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.