删除Codeigniter HMVC中的index.php

时间:2016-12-19 20:22:51

标签: codeigniter hmvc-codeigniter

我尝试删除Codeigniter HMVC中的index.php。但我无法完成以下代码。

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

我将.htaccess文件放在根目录中,并从配置文件中删除了index.php。我仍然面临同样的问题。

4 个答案:

答案 0 :(得分:1)

在你的config.php文件中

$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";

然后在.htaccess文件中输入

<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>

现在,检查你的网址删除index.php。它会起作用。

答案 1 :(得分:1)

请按照以下步骤操作:

  1. 转到application / config / config.php: 将$config['index_page'] = 'index.php';替换为$config['index_page'] = '';$config['uri_protocol'] = 'REQUEST_URI';$config['uri_protocol'] = 'AUTO';

  2. 启用重写模式  sudo a2enmod rewrite 然后 service apache2 restart

  3. 如果您愿意,可以使用以下.htaccess文件。

  4. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>

答案 2 :(得分:0)

只需创建一个新文件.htaccess。

并将以下代码粘贴到.htaccess文件中。

然后进入项目文件夹,遵循路径 application-> config-> config.php

进入config.php文件

$ config ['index_page] ='index.php';替换为$ config ['index_page'] ='';


RewriteEngine on

RewriteCond%{REQUEST_FILENAME}!-f

RewriteCond%{REQUEST_FILENAME}!-d

RewriteRule ^(。*)$ /example/index.php/$1 [L]

//到上面的行示例中是项目名称,您必须将示例替换为您的项目名称

答案 3 :(得分:0)

getAttribute
相关问题