2015-10-30 57 views
0

我想在Codeigniter 3中實現分頁,但它始終給404頁找不到錯誤。我正在使用htaccess文件來隱藏index.php。Codeigniter 3與htaccess分頁不工作

我的控制器功能是

$config = array(); 
$config['base_url'] = base_url('gallery'); 
$total_row = $this->gallery_model->record_count(); 
$config["total_rows"] = $total_row; 
$config["per_page"] = 5; 
$config['use_page_numbers'] = TRUE; 
$config['num_links'] = $total_row; 
$config['uri_segment'] = '4'; 
$config['cur_tag_open'] = '&nbsp;<a class="current">'; 
$config['cur_tag_close'] = '</a>'; 
$config['next_link'] = 'Next'; 
$config['prev_link'] = 'Previous'; 

$this->pagination->initialize($config); 

if($this->uri->segment(2)) 
{ 
    $page = ($this->uri->segment(2)) ; 
} 
else 
{ 
    $page = 1; 
} 
$data["results"] = $this->gallery_model->fetch_data($config["per_page"], $page); 

.htaccess的是如下

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /lifeschool-genius/ 

### Canonicalize codeigniter URLs 

# If your default controller is something other than 
# "welcome" you should probably change this 
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$/[L,R=301] 
RewriteRule ^(.*)/index/?$ $1 [L,R=301] 

# Removes trailing slashes (prevents SEO duplicate content issues) 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)/$ $1 [L,R=301] 

# Enforce www 
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator 
# RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC] 
# RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301] 

# Enforce NO www 
# RewriteCond %{HTTP_HOST} ^www [NC] 
# RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301] 

### 

# Removes access to the system folder by users. 
# Additionally this will allow you to create a System.php controller, 
# previously this would not have been possible. 
# 'system' can be replaced if you have renamed your system folder. 
RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php/$1 [L] 

# Checks to see if the user is attempting to access a valid file, 
# such as an image or css document, if this isn't true it sends the 
# request to index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
# Without mod_rewrite, route 404's to the front controller 
ErrorDocument 404 /index.php 
</IfModule> 

我的路線文件

$route['(:any)'] = "welcome/$1"; 
$route['default_controller'] = 'welcome'; 
$route['404_override'] = ''; 
$route['translate_uri_dashes'] = FALSE; 

我曾與笨2之前使用相同的代碼在另一個項目它用於正常工作。請讓我知道這有什麼問題

任何幫助將不勝感激。

感謝

+0

閱讀這兩個環節可以幫助你http://w3code.in/2015/10/how-to-do-pagination-in-codeigniter/和http://w3code.in/2015/ 09 /如何去除的指數的PHP文件從 - 笨-URL / – Ricky

回答

0

更改這些

$config['base_url'] = base_url().'gallery'; 
$config['uri_segment'] = '1'; 
if($this->uri->segment(1)) 
{ 
    $page = ($this->uri->segment(1)) ; 
} 

有衝突代碼

$config['uri_segment'] = '4'; 

if($this->uri->segment(2)) 
{ 
    $page = ($this->uri->segment(2)) ; 
} 
0

在笨3,所有的(控制器,模型,librarues)的文件名應以大寫字母開頭。

也可以嘗試改變你的htacess這樣,

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