我在子域上有一个 CodeIgniter 项目。现在,当我访问sub.example.com它时加载login page并成功登录,它重定向到仪表板。一旦登录并且会话就位,访问sub.example.com/login/将自动重定向到dashboard page. 现在这是我的问题。成功登录后,访问sub.example.com不会重定向到任何地方,它只是加载登录页面。但是访问sub.example.com/index.php确实将我重定向到仪表板页面。出于某种原因,我的索引方法被调用或正常工作。这是我的代码。.htaccessIndexIgnore *php_value date.timezone Asia/KolkataRewriteEngine onRewriteCond $1 !^(index\.php|resources|robots\.txt)RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1 [L,QSA]## Remove www from URLRewriteCond %{HTTP_HOST} ^www\.RewriteRule ^(.*)$ https://sub.example.com/$1 [R=301,L]## Redirect to HTTPSRewriteCond %{HTTPS} offRewriteCond %{HTTP_HOST} ^sub.example.com$RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}配置文件if ($_SERVER['REMOTE_ADDR'] == "127.0.0.1") { $config['base_url'] = "http://" . $_SERVER['SERVER_NAME'];} else { $config['base_url'] = "https://" . $_SERVER['SERVER_NAME'];}路由文件$route['default_controller'] = 'root';$route['root_controller'] = 'root';/*API CONTROLLER*/$route['api_controller'] = 'api';/*Guest Controller*/$route['guest_controller'] = 'guest';/*Custom Routes*/$route['dashboard/(:any)'] = 'root/dashboard/$1';$route['search/(:any)'] = 'root/search/$1';$route['search/(:any)/(:num)'] = 'root/search/$1/$2';$route['export/(:any)'] = 'root/export/$1';根控制器public function __construct() { parent::__construct(); $this->default_data = array("project_name" => PROJECT_NAME); if ($this->router->method == "privacy_policy") { return; } $this->load->library('session'); if ($this->router->method == "login") { if ($this->session->userdata("username")) { redirect(base_url("dashboard/")); } } else { if (!$this->session->userdata("username")) { redirect(base_url("login/")); } } //Set MYSQL timezone $this->db->query("SET time_zone = '+05:30'"); }
3 回答
江户川乱折腾
TA贡献1851条经验 获得超5个赞
Hers 是一个想法 - 在加载会话对象后添加:
if ($this->session->userdata("username") && $this->router->method == "index") {
redirect(base_url("dashboard/"));
}
沧海一幻觉
TA贡献1824条经验 获得超5个赞
请使用这个.htaccess
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
- 3 回答
- 0 关注
- 149 浏览
添加回答
举报
0/150
提交
取消