url 中的 codeigniter 3 控制器索引(无 index.php)

codeigniter 3 controller index in url ( no index.php )

我一直在尝试从我的 url 中删除索引,但没有成功,当我说索引时我的意思是 www.mywebsite。com/en/controller/index 而不是 www.mywebsite。 com/index.php

我正在使用 codeigniter 3,我在 ubuntu 16.04 所以没有 httpd.conf 但 mywebsite.com.conf mod 重写已激活,我有另一个使用 codeigniter 2 的项目,它运行良好。

这是我的 .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]
</IfModule>

感谢这个插件,我正在使用多语言网站 http://jeromejaglale.com/doc/php/codeigniter_i18n

在我的路由中我有

$route['default_controller'] = 'App';
$route['404_override'] = 'site_404';

$route['translate_uri_dashes'] = TRUE;    

if ($this->config->item('multilanguage')):          
    $route['^(en|fr)/(.+)$'] = "";
    $route['^(en|fr)$'] = "";         
endif;

在我的控制器中我有这个

class App extends MX_Controller {

    function __construct()
    {
        parent::__construct();
        header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
    }

    public function index()
    {
      /*I load my view here*/
    }
}

我也打算使用多个控制器和多个方法 我一直在寻找解决方案,但我总是找到关于 index.php 的解决方案,而不是控制器中的实际方法(它保留在 url )

将此作为第一条规则放在 RewriteEngine On 之后(也可以将 RewriteBase 设置为适当的位置):

RewriteEngine On
RewriteBase /

# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$  [L,R=301]