我正在尝试在 CodeIgniter 上使用 .htaccess
,但它不起作用。
我已经设置了:
AllowOverride All
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
我在 Windows 上使用 XAMPP。
我的.htaccess
:
RewriteEngine On
RewriteCond $1 !^(index\.php|images|scripts|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
我的 URL 仍然包含 index.php
,如果我尝试手动删除它,它会返回 404 错误
我的另一个问题是我的登录页面:每当我登录时,我的 URL 都停留在检查页面上。
我想知道如何重写我的 URL 以更改为主页而不是停留在检查页面上。
public function check(){
$this->load->model('check');
$logcheck = $this->check->check($this->input->post('username'),$this->input->post('password'));
if($logcheck == "admin"){
$this->load->view('home');
}else{
$this->load->view('login');
}
}
最佳答案
这个简单的 .htaccess 将删除您的 index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
像这样更改您的检查功能
public function check(){
$this->load->model('check');
$logcheck = $this->check->check($this->input->post('username'),$this->input->post('password'));
if($logcheck == "admin"){
//may be you need to set login credential into session
redirect('Phonebook/home/');
//$this->load->view('home');
}else{
$this->load->view('login');
}
}
你的主页功能将是这样的
public function home(){
//remember you need to check login validation from session
$this->load->view('home');
}
要使用 redirect
函数,请记住您已加载 url
帮助程序。
也许这对你有帮助
关于php - Codeigniter Htaccess 和 URL 重定向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28517126/