2016-11-08 159 views
0

我遇到了這個問題與URL中的index.php,從而當其刪除鏈接到我的控制器不再工作?Codeigniter - 刪除index.php導致鏈接中斷

我已經修改了以下內容:

的config.php:

$config['index_page'] = ''; 

URI協議是因爲是:

$config['uri_protocol'] = 'REQUEST_URI'; 

的.htaccess:

RewriteEngine On 
RewriteBase /ampp/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L] 

我也已使用phpinfo();驗證模塊mod_rewrite已加載。

當前URL的格式如下: http://localhost:100/ampp/

主要頁面上的登錄表單:

<form class="form-signin" method="POST" action="<?php echo site_url('Auth/login') ?>"> 
    <span id="reauth-email" class="reauth-email"></span> 

    <input type="email" id="inputEmail" class="form-control" placeholder="Email" name="email" required autofocus> 
    <input type="password" id="inputPassword" class="form-control" placeholder="Password" name="password" required> 
    <br> 
    <button type="submit" name="submit" value="submit" class="btn btn-lg btn-primary btn-block btn-signin">Sign in</button> 
</form> 

然而,當我提出我得到404

Not Found 

The requested URL /ampp/Auth/login was not found on this server. 

我形式已檢查日誌文件以查看問題是什麼,但日誌文件只是表示未找到Auth。

File does not exist: /var/www/html/ampp/Auth, referer: http://localhost:100/ampp/ 

技術上的文件不在日誌文件中聲稱,但我想到笨會妥善解決這個(如文件是/最低團費/應用/控制器/這是真的)的目錄。

樹結構

. 
├── cache 
│   └── index.html 
├── config 
│   ├── autoload.php 
│   ├── config.php 
│   ├── constants.php 
│   ├── database.php 
│   ├── doctypes.php 
│   ├── foreign_chars.php 
│   ├── hooks.php 
│   ├── index.html 
│   ├── memcached.php 
│   ├── migration.php 
│   ├── mimes.php 
│   ├── profiler.php 
│   ├── routes.php 
│   ├── smileys.php 
│   └── user_agents.php 
├── controllers 
│   ├── Auth.php 
│   ├── Home.php 
│   ├── index.html 
│   ├── Login.php 
│   └── Main.php 
├── core 
│   └── index.html 
├── helpers 
│   └── index.html 
├── hooks 
│   └── index.html 
├── index.html 
├── language 
│   ├── english 
│   │   └── index.html 
│   └── index.html 
├── libraries 
│   └── index.html 
├── logs 
│   └── index.html 
├── models 
│   ├── index.html 
│   ├── UserAuth.php 
│   └── User.php 
├── third_party 
│   └── index.html 
└── views 
    ├── errors 
    │   ├── cli 
    │   │   ├── error_404.php 
    │   │   ├── error_db.php 
    │   │   ├── error_exception.php 
    │   │   ├── error_general.php 
    │   │   ├── error_php.php 
    │   │   └── index.html 
    │   ├── html 
    │   │   ├── error_404.php 
    │   │   ├── error_db.php 
    │   │   ├── error_exception.php 
    │   │   ├── error_general.php 
    │   │   ├── error_php.php 
    │   │   └── index.html 
    │   └── index.html 
    ├── home.php 
    ├── index.html 
    ├── login.php 
    └── report.php 

Auth.php控制器

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Auth extends CI_Controller { 

     public function __construct() { 
       parent::__construct(); 
       $this->load->model('UserAuth'); 

       $this->output->set_header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT'); 
       $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate'); 
       $this->output->set_header('Cache-Control: post-check=0, pre-check=0',false); 
       $this->output->set_header('Pragma: no-cache'); 
     } 
     public function index() { 
       $session = $this->session->userdata('authUser'); 
       if(!$session) { 
         redirect('login','refresh'); 
       } else { 
         $this->propagate($session['id']); 
       } 
     } 
     public function login() { 
       $this->verifylogin(); 
     } 
     public function verifylogin() { 
       $email = $this->input->post('email'); 
       $password = $this->input->post('password'); 

       $data = array('email'=>$email, 'password'=>$password); 
       $validation = $this->UserAuth->validateUser($data); 

       if($validation == false) { 
         //show login with erro message - no error message implemented 
         $this->load->view('login'); 
       } else { 
         $result = $validation; 
         $sess_array = array(); 
         foreach($result as $row) { 
           $sess_array = array(
             'authID' => sha1($result[0]->id), 
             'id' => $result[0]->id, 
             'email' => $result[0]->email 
             ); 
           $this->session->set_userdata('authUser', $sess_array); 
         } 
         redirect('home','refresh'); 
       } 
     } 
     public function logout() { 
       $this->session->unset_userdata('authUser'); 
       $this->session->sess_destroy(); 
       redirect('Main', 'refresh'); 
     } 
} 

的.htaccess檢查

我想我給它一個去,它似乎是它可以成爲實際的問題文件。爲什麼?

好吧,我已經更換了.htaccess文件的內容與此:

order deny,allow 
deny from all 

但我仍然能看到主登錄頁面(儘管事實上的.htaccess不應該讓我)

更新: 好,因爲我已經注意到,任何.htaccess文件不工作,我去挖掘找出爲什麼它不工作。

因此,問題是與虛擬主機配置...

<Directory "/"> //<-------- This was the issue. 
    AllowOverride All 
    Order Allow,Deny 
    Allow from all 
</Directory> 


<Directory "/var/www/html/ampp"> //<------- This has resolved then issue. 
    AllowOverride All 
    Order Allow,Deny 
    Allow from all 
</Directory> 
+0

嘗試取出'RewriteBase'和改變該線'重寫規則^(。*)$的index.php/$ 1 [L]''到重寫規則^(。*)$ /ampp/index.php/$1 [L]',這是我的設置。 – Blinkydamo

+0

@Blinkydamo Nope - 還有同樣的問題 –

+0

請記住,你也應該在codeigniter中設置base_url – killstreet

回答

0

所以事實證明,這個問題是不是與.htaccess它的自我也不是Codeigniter,而是Apache配置。

<Directory "/"> //<-------- This was the issue. 
    AllowOverride All 
    Order Allow,Deny 
    Allow from all 
</Directory> 


<Directory "/var/www/html/ampp"> //<------- This has resolved then issue. 
    AllowOverride All 
    Order Allow,Deny 
    Allow from all 
</Directory> 
0

我假設你的認證是一個控制器類,登錄是該類的一種方法。只需檢查你的類文件的文件名,即檢查你的驗證控制器的文件名,它應該是第一個字符大寫,「Auth.php」。然後將您的表單的動作更改爲

site_url('auth/login') 

注意:在URL中使用小寫字母auth。

希望它能解決您的問題。

+0

也可以嘗試在你的htaccess中添加斜槓「/」index.php的infront – puncoz

+0

即'RewriteRule ^(。* )$ /index.php/$1 [L]' – puncoz

+0

我不認爲小寫會是問題 –

0

更改.htaccess這個

RewriteEngine on 
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

在配置

$config['base_url'] = 'http://localhost:100/ampp/'; 

形式

<form class="form-signin" method="POST" action="<?php echo base_url();?>auth/login"> 

在此之前,確保有控制通話auth和方法調用login

+0

仍然相同的問題 –

+0

你改變什麼,在哪裏? –

+0

我已經應用了你的建議.htaccess,但問題仍然存在。 –