我正在使用CodeIgniter 3,并且在让路由器在我的开发环境中工作时遇到了问题。文件的相关部分:
网站/ .htaccess文件:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
site / application / config / routes.php文件:
$route['default_controller'] = 'auth/login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['page/(:any)'] = 'page/view/$1';
网站/应用/配置/ config.php中:
$config['base_url'] = 'http://localhost/~me/site/';
$config['index_page'] = '';
网站/应用/控制器/ page.php文件
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Page extends CI_Controller {
public function view($page = 'about')
{
if (!$this->ion_auth->logged_in()) {
redirect('auth/login');
}
if ( ! file_exists(APPPATH.'/views/page/'.$page.'.php')) {
show_404();
}
$this->load->view('templates/header');
$this->load->view('page/'.$page);
$this->load->view('templates/footer');
}
结果:
localhost/~me/site takes me to login as expected (routes.php is being called)
localhost/~me/site/index.php/page/view/about works (basic logic works)
localhost/~me/site/index.php/page/about works ($route['page/(:any)'] works)
但是,我想要使用的是:localhost / ~me / site / page / about about:
The requested URL /index.php/page/about was not found on this server
我在localhost / ~me / site / page / view / about
中得到了同样的错误所以看起来好像只接触到routes.php: a)明确地调用index.php,或者 b)在没有任何扩展名的情况下呼叫路由
任何帮助将不胜感激!
答案 0 :(得分:0)
在.htaccess文件中尝试此操作
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
答案 1 :(得分:0)
您是否已将 AllowOverride All 指令放入Apache配置文件或虚拟主机配置文件中?