1

目前我正在尝试学习 CodeIgniter。

这有效:

 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';
4

2 回答 2

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]
于 2013-02-10T18:37:46.980 回答
1

看看文档

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]
于 2013-02-10T18:37:59.010 回答