2013-02-10 65 views
0

目前我正在學習CodeIgniter。Codeigniter重寫,如何跳過index.php?

這工作:

http://localhost/NewsPage/index.php/news/fenerana 

但我想讓它時,它是工作:

http://localhost/NewsPage/news/fenerana 

我怎樣才能做到這一點? 我現在的routes.php文件的文件是:

$route['news/(:any)'] = 'news/view/$1'; 
$route['news'] = 'news'; 
$route['(:any)'] = 'pages/view/$1'; 
$route['default_controller'] = 'pages/view'; 

回答

1

看看在documentation

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

我的建議,雖然是使用此版本:

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

謝謝。我的.htaccess文件目前是:RewriteEngine敘述在 的RewriteCond%{} REQUEST_FILENAME -f 的RewriteCond%{} REQUEST_FILENAME -d 重寫規則^ $的index.php/$ 1 [L] 所有 但是拒絕,!(*)。它不工作? – 2013-02-10 18:46:42

+0

謝謝你,我讓它工作.. – 2013-02-10 18:48:30

2

首先去的application/config/config.php文件並打開 'index_page' 空:

$config['index_page'] = ''; 

然後使用的.htaccess(把它放在同級別CI的index.php),像這樣:

DirectoryIndex index.php 
RewriteEngine on 
RewriteCond $1 !^(index\.php|images_folder|css_folder_maybe) 
RewriteRule ^(.*)$ ./index.php/$1 [L] 
+0

什麼是DirectoryIndex的? – 2013-02-10 19:03:53

+0

當客戶端通過在目錄名稱末尾指定/來請求目錄的索引時,DirectoryIndex指令設置要查找的資源列表。更多信息: http://httpd.apache.org/docs/2.2/mod/mod_dir.html – mallix 2013-02-10 20:52:27