2013-11-24 78 views
5

我有一个为codeigniter 2.1.4中的客户端开发的小项目,他现在坚持迁移到codeigniter 3 DEV版本。我知道这不是一个好的理念,但... 我的问题是,我无法从url中删除index.php。Codeigniter 3删除index.php问题

这是我的.htaccess文件:

Options +FollowSymLinks 
    RewriteEngine on 

    # Send request via index.php 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 

我从config.php文件删除的index.php
没有运气
我重新安装了LAMP服务器(我是在Ubuntu 12.04' ),重新配置
我在Codeigniter 2.1.4和Laravel 4上开发的本地服务器上有其他项目,它们工作得很好,但是这个项目让我很难过。
谢谢!

+0

只是出于好奇:你的客户如何区分版本2和3,但不能转换自己? –

+0

@php_nub_qq ya,无论如何,我正在读CI3的全部内容:@ –

+1

他不得不在某个人的脑袋里推这个东西。 – Chiribuc

回答

2

如果您的Apache服务器启用了mod_rewrite,您可以通过使用带有一些简单规则的.htaccess文件轻松删除此文件。

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

取出?的index.php

-1

后,我再次克隆Git仓库,并提出了全新安装的灯,现在它的工作原理。

6

请下面的代码直接添加到的.htaccess文件并将其包含到您/codeigniter_project_folder/.htacess

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

你的CI项目的根目录中创建新的.htaccess文件,并添加代码那里。不要更改应用程序文件夹中的.htaccess文件。这是为我工作

0

刚刚从根下载CI版本2.2.0

复制.htaccesshtaccess.txt并粘贴在你的笨3项目。

不要忘记从.htaccess文件更改项目名称。

11

我做了这样:

创造了的.htaccess与内容项目的根文件夹:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond $1 !^(index\.php|css|js|images|robots\.txt) 
RewriteRule ^(.*)$ index.php?$1 [L] 

然后,在config.php中我修改了这一行。

来源:

$config['url_suffix'] = 'index.php'; 

要:

$config['url_suffix'] = ''; 
0
  1. 创建您的www/project_folder一个新的htaccess的文件或您的htdocs/project_folder

  2. 确保mod_rewrite的是使用我的使用echo phpinfo()

  3. 只需粘贴下面的代码,它应该工作:

    <IfModule mod_rewrite.c> 
    
        RewriteEngine on 
        RewriteCond $1 !^(index\.php|images|robots\.txt) 
        RewriteRule ^(.*)$ /project_folder/index.php/$1 [L] 
    </IfModule> 
    
    <IfModule !mod_rewrite.c> 
        ErrorDocument 404 /index.php 
    </IfModule> 
    
  4. 改变项目文件夹到自己的

2

添加以下行的.htaccess文件

RewriteCond %{REQUEST_URI} ^/system.* 
RewriteRule ^(.*)$ index.php?/$1 [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ index.php?/$1 [L] 

还编辑application/config/config.php文件。与

$config[‘index_page’] = “”; 
$config[‘uri_protocol’] = “AUTO“; 

它会工作。

1
  1. 做一个.htacess文件在你的项目的根文件夹/Your_codeigniter_project_folder/.htacess并粘贴此代码

    RewriteEngine叙述在

    的RewriteCond%{} REQUEST_FILENAME -f

    的RewriteCond%{} REQUEST_FILENAME! - d

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

  2. 设置的基准URL在config.php文件$config['base_url'] = 'http://yourhost/CI_project_folder/';

  3. 组URL后缀$config['url_suffix'] = '.php';

*如果不起作用请检查此*

  • 请确保在根文件夹中.htacess停留在那里没有任何文件的名称与您的控制器名称相同。 例子:你有一个users.php控制器还你有/Your_codeigniter_project_folder/users.php 一个文件,如果有,请删除它/Your_codeigniter_project_folder/users.php

  • 确保你的服务器上(从该行开始删除#)

    的LoadModule rewrite_module改写模式模块/ mod_rewrite的。所以