使用CodeIgniter删除url中的index.php
我正在开发一个基于Ubuntu、Apache2和CodeIgniter的应用程序 我有一个名为使用CodeIgniter删除url中的index.php,php,apache,codeigniter,Php,Apache,Codeigniter,我正在开发一个基于Ubuntu、Apache2和CodeIgniter的应用程序 我有一个名为Site的控制器,如下所示 class Site extends CI_Controller { public function view($page = 'home') { $this->load->view('site/'.$page, $data); } } 在application/views/site中,我有home.php和about.p
Site
的控制器,如下所示
class Site extends CI_Controller {
public function view($page = 'home')
{
$this->load->view('site/'.$page, $data);
}
}
在application/views/site
中,我有home.php
和about.php
localhost/index.php/about
运行良好但是
localhost/about
get未找到,在此服务器上未找到请求的URL/about。
我已经
$config['index_page']=''
inapplication/config/config.php
$route['default_controller'] = "site/view";
$route['404_override'] = '';
$route['(:any)'] = "site/view/$1";
这是我的.htaccess
:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
重新编写引擎打开
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L]
上的AcceptPathInfo
这是我正在使用的.htaccess(在Yii上,但应该是可交换的):
与您的几乎相同请尝试跟随本页了解。你的规则看起来是正确的,但我对正则表达式很糟糕
需要研究的一些事情是使用phpinfo()检查mod_rewrite是否可用;。该链接中的第三步还讨论了使用a2enmod启用mod_重写。并确保从我的codeigniter网站重新启动Apache。
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
重新启动发动机
1美元^(索引\.php | resources | robots\.txt)
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L,QSA]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>