繁体   English   中英

使用CodeIgniter删除网址中的index.php

[英]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.phpabout.php

localhost/index.php/about运作良好
但是localhost/about得到
Not Found,The requested URL /about was not found on this server.

我已经

  1. 确保apache2配置文件中的mod_rewrite打开并且AllowOverride All
  2. $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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM