I am using CodeIgniter 3 and am having problems getting the router to work in my development environment. Relevant portions of files:
site/.htaccess file:
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 file:
$route['default_controller'] = 'auth/login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['page/(:any)'] = 'page/view/$1';
site/application/config/config.php:
$config['base_url'] = 'http://localhost/~me/site/';
$config['index_page'] = '';
site/application/controllers/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');
}
Results:
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)
But, what I want to use is: localhost/~me/site/page/about which gives:
The requested URL /index.php/page/about was not found on this server
I get the same error with localhost/~me/site/page/view/about
So it seems as if routes.php is only reached if I either: a) call out index.php explicitly, or b) call the route without any extension
Any help would be appreciated!
Try this in your .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
您是否将AllowOverride All指令放置到您的Apache配置文件或虚拟主机配置文件中?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.