我试图在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'); }