Codeigniter 3删除索引。php的问题

时间:2022-10-06 22:48:06

I have a little project that i developed for a client in codeigniter 2.1.4 and now, he insists to migrate to codeigniter 3 DEV version. I know that's not a good ideea but... My problem is that i can't remove the index.php from the url.

我在codeigniter 2.1.4中为客户开发了一个小项目,现在他坚持要迁移到codeigniter 3 DEV版本。我知道这不是个好主意,但是……我的问题是我不能删除索引。php从url。

This is my .htaccess file :

这是我的。htaccess文件:

  Options +FollowSymLinks
  RewriteEngine on

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

I have removed the index.php from the config.php file
No luck
I reinstalled the LAMP server (i'm on Ubuntu 12.04'), reconfigured
I have other projects on my local server developed on Codeigniter 2.1.4 and Laravel 4 and they work just fine but this one it's killing me.
Thank you!

我已经删除了索引。php的配置。我重新安装了LAMP服务器(我在Ubuntu 12.04'上),在Codeigniter 2.1.4和Laravel 4上开发了本地服务器上的其他项目,它们运行得很好,但这一个却让我崩溃。谢谢你!

9 个解决方案

#1


11  

I made this way:

我做了:

Created the .htaccess in the root folder of the project with the content:

在项目的根文件夹中创建.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]

Then, in the config.php i modified this line.

然后,在配置。php我修改了这一行。

From:

来自:

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

To:

:

$config['url_suffix'] = '';

#2


6  

Kindly add the below codes to .htaccess file and include it directly to your /codeigniter_project_folder/.htacess

请将以下代码添加到.htaccess文件,并将其直接包含到/codeigniter_project_folder/.htacess中

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

#3


2  

If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules.

如果您的Apache服务器已经启用了mod_rewrite,那么您可以使用一个带有一些简单规则的.htaccess文件来删除这个文件。

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

Remove the ? after index.php

删除吗?在index . php

#4


2  

Add following lines in .htaccess file

在.htaccess文件中添加以下行

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

And also Edit application/config/config.php file. with

编辑应用程序/配置/配置。php文件。与

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

It will Work.

它将工作。

#5


1  

  1. Make a .htacess file in your project root folder /Your_codeigniter_project_folder/.htacess and paste this code

    在项目根文件夹/Your_codeigniter_project_folder/中创建一个.htacess文件。htacess并粘贴此代码

    RewriteEngine On

    RewriteEngine上

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond % { REQUEST_FILENAME } ! - f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond % { REQUEST_FILENAME } ! - d

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

    RewriteRule ^(. *)美元指数。php / 1美元[L]

  2. set a base URL in config.php file $config['base_url'] = 'http://yourhost/CI_project_folder/';

    在配置中设置一个基本URL。php文件$config['base_url'] = 'http://yourhost/CI_project_folder/';

  3. set URL suffix $config['url_suffix'] = '.php';
  4. 设置URL后缀$config['url_suffix'] = '.php';

* If not work please check this *

*如果不工作请检查这个*

  1. Make sure in your root folder where .htacess stay there have not any file which name is same like your controller name. Example: you have a users.php controller also you have a file in /Your_codeigniter_project_folder/users.php If have please remove it /Your_codeigniter_project_folder/users.php

    确保在.htacess所在的根文件夹中没有任何文件名与控制器名相同的文件。例子:你有一个用户。php控制器也有一个文件in /Your_codeigniter_project_folder/users。如果有的话,请删除它/Your_codeigniter_project_folder/user .php。

  2. Make sure your server is rewrite mode on( remove # from start of this line)

    确保您的服务器正在重新编写模式(从本行开始删除#)

    LoadModule rewrite_module modules/mod_rewrite.so

    / mod_rewrite.so LoadModule rewrite_module模块

#6


0  

create new .htaccess file on root of your CI project and add your code there. Do not change .htaccess file on application folder. That's work for me

在CI项目的根上创建新的.htaccess文件,并在其中添加代码。不要更改应用程序文件夹上的.htaccess文件。这对我的工作

#7


0  

Just Download CI version 2.2.0

下载CI版本2.2.0

Copy .htaccess and htaccess.txt from root and paste it in your Codeigniter 3 project.

复制htaccess . htaccess。txt从根中粘贴到Codeigniter 3项目中。

Don't forget to change project name from .htaccess file.

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

#8


0  

  1. Create an a new htaccess file in your www/project_folder or your htdocs/project_folder

    在您的www/project_folder或htdocs/project_folder中创建一个新的htaccess文件

  2. Make sure mod_rewrite is working my using echo phpinfo()

    确保mod_rewrite使用echo phpinfo()

  3. Simply paste the following code and it should work:

    只需粘贴以下代码,它就会工作:

    <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. Change the project folder to that of your own

    将项目文件夹更改为您自己的文件夹

#9


-1  

I have clone the git repository again and made a clean install of the lamp and now it works.

我再次克隆了git存储库,并对lamp进行了干净的安装,现在它可以工作了。

#1


11  

I made this way:

我做了:

Created the .htaccess in the root folder of the project with the content:

在项目的根文件夹中创建.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]

Then, in the config.php i modified this line.

然后,在配置。php我修改了这一行。

From:

来自:

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

To:

:

$config['url_suffix'] = '';

#2


6  

Kindly add the below codes to .htaccess file and include it directly to your /codeigniter_project_folder/.htacess

请将以下代码添加到.htaccess文件,并将其直接包含到/codeigniter_project_folder/.htacess中

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

#3


2  

If your Apache server has mod_rewrite enabled, you can easily remove this file by using a .htaccess file with some simple rules.

如果您的Apache服务器已经启用了mod_rewrite,那么您可以使用一个带有一些简单规则的.htaccess文件来删除这个文件。

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

Remove the ? after index.php

删除吗?在index . php

#4


2  

Add following lines in .htaccess file

在.htaccess文件中添加以下行

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

And also Edit application/config/config.php file. with

编辑应用程序/配置/配置。php文件。与

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

It will Work.

它将工作。

#5


1  

  1. Make a .htacess file in your project root folder /Your_codeigniter_project_folder/.htacess and paste this code

    在项目根文件夹/Your_codeigniter_project_folder/中创建一个.htacess文件。htacess并粘贴此代码

    RewriteEngine On

    RewriteEngine上

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond % { REQUEST_FILENAME } ! - f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond % { REQUEST_FILENAME } ! - d

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

    RewriteRule ^(. *)美元指数。php / 1美元[L]

  2. set a base URL in config.php file $config['base_url'] = 'http://yourhost/CI_project_folder/';

    在配置中设置一个基本URL。php文件$config['base_url'] = 'http://yourhost/CI_project_folder/';

  3. set URL suffix $config['url_suffix'] = '.php';
  4. 设置URL后缀$config['url_suffix'] = '.php';

* If not work please check this *

*如果不工作请检查这个*

  1. Make sure in your root folder where .htacess stay there have not any file which name is same like your controller name. Example: you have a users.php controller also you have a file in /Your_codeigniter_project_folder/users.php If have please remove it /Your_codeigniter_project_folder/users.php

    确保在.htacess所在的根文件夹中没有任何文件名与控制器名相同的文件。例子:你有一个用户。php控制器也有一个文件in /Your_codeigniter_project_folder/users。如果有的话,请删除它/Your_codeigniter_project_folder/user .php。

  2. Make sure your server is rewrite mode on( remove # from start of this line)

    确保您的服务器正在重新编写模式(从本行开始删除#)

    LoadModule rewrite_module modules/mod_rewrite.so

    / mod_rewrite.so LoadModule rewrite_module模块

#6


0  

create new .htaccess file on root of your CI project and add your code there. Do not change .htaccess file on application folder. That's work for me

在CI项目的根上创建新的.htaccess文件,并在其中添加代码。不要更改应用程序文件夹上的.htaccess文件。这对我的工作

#7


0  

Just Download CI version 2.2.0

下载CI版本2.2.0

Copy .htaccess and htaccess.txt from root and paste it in your Codeigniter 3 project.

复制htaccess . htaccess。txt从根中粘贴到Codeigniter 3项目中。

Don't forget to change project name from .htaccess file.

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

#8


0  

  1. Create an a new htaccess file in your www/project_folder or your htdocs/project_folder

    在您的www/project_folder或htdocs/project_folder中创建一个新的htaccess文件

  2. Make sure mod_rewrite is working my using echo phpinfo()

    确保mod_rewrite使用echo phpinfo()

  3. Simply paste the following code and it should work:

    只需粘贴以下代码,它就会工作:

    <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. Change the project folder to that of your own

    将项目文件夹更改为您自己的文件夹

#9


-1  

I have clone the git repository again and made a clean install of the lamp and now it works.

我再次克隆了git存储库,并对lamp进行了干净的安装,现在它可以工作了。