从CodeIgniter URL中删除index.php

时间:2017-02-25 11:20:04

标签: php apache .htaccess codeigniter mod-rewrite

我正在努力删除CodeIgniter URL的'index.php'部分。 我正在使用CodeIgniter 3.1.2版。我已经对其他问题采取了所有步骤:

  • $config['index_page'] = 'index.php'更改为$config['index_page'] = ''
  • $config['uri_protocol'] = 'AUTO'更改为$config['uri_protocol'] = 'REQUEST_URI'
  • 使用以下代码在项目的根文件夹中添加了.htaccess文件:

RewriteEngine on RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]

但是,当我尝试访问我的网站时,我收到以下错误代码。

  

未找到

     

在此服务器上找不到请求的URL / Toneel / Site / index。

我的Apache服务器中打开了重写模块。 任何人都可以帮我解决这个问题吗?

4 个答案:

答案 0 :(得分:4)

此设置对我有用。

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

的.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

要允许覆盖Apache配置中的htaccess,您必须编辑并将/apache2.conf文件更改为

AllowOverride All

然后重新启动服务器。

答案 1 :(得分:1)

在.htaac​​ess中尝试此代码:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]

答案 2 :(得分:0)

在.htaccess文件中尝试此操作

RewriteEngine On
RewriteBase /yourfolderhere/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

答案 3 :(得分:0)

就我而言,它适用于:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /project-name

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^ index.php [QSA,L]
</IfModule>

**重要的是,这应该位于项目根目录中的.htaccess文件中。

config 中应该是这样的:

$config['base_url'] = 'http://your-url-here/';
$config['index_page'] = '';
相关问题