![](/img/trans.png)
[英]How to remove index.php from URL in CodeIgniter using .htaccess
[英]remove index.php in url using 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.php
localhost/index.php/about
运作良好
但是localhost/about
得到
Not Found,The requested URL /about was not found on this server.
我已经
mod_rewrite
打开并且AllowOverride All
。 $config['index_page'] = '';
在application/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>
这是我正在使用的.htaccess(在Yii上,但应该可以互换):
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
几乎和你一样
尝试关注此页面有关codeignitor漂亮的url的信息 。 您的规则看起来正确,但是使用正则表达式太糟糕了。
需要考虑的一些事情是通过使用phpinfo();检查mod_rewrite是否可用。 该链接中的第三步还讨论了使用a2enmod启用mod_rewrite。 并确保重新启动Apache。
从我的codeigniter网站上。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.