Codeigniter 3 删除index.php问题

问题描述 投票:0回答:11

我有一个在 codeigniter 2.1.4 中为客户开发的小项目,现在他坚持迁移到 codeigniter 3 DEV 版本。我知道这不是一个好主意但是... 我的问题是我无法从网址中删除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 上开发的,它们工作得很好,但这一个简直要了我的命。
谢谢!

php apache .htaccess codeigniter mod-rewrite
11个回答
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'] = '';

6
投票

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

 重写引擎开启
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L]

2
投票

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

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

删除index.php后面的

?


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. 在 config.php 文件中设置基本 URL

    $config['base_url'] = 'http://yourhost/CI_project_folder/';

  3. 设置网址后缀
    $config['url_suffix'] = '.php';

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

  1. 确保

    .htacess
    所在的根文件夹中没有任何名称与控制器名称相同的文件。 示例:您有一个
    users.php
    控制器,并且您在
    /Your_codeigniter_project_folder/users.php
    中有一个文件 如果有请删除它
    /Your_codeigniter_project_folder/users.php

  2. 确保您的服务器处于重写模式(从该行开头删除#)

    LoadModule rewrite_module 模块/mod_rewrite.so


0
投票

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


0
投票

只需下载CI版本

2.2.0

从根目录复制

.htaccess
htaccess.txt
并将其粘贴到您的 Codeigniter 3 项目中。

不要忘记从

.htaccess
文件更改项目名称。


0
投票
  1. 在 www/project_folder 或 htdocs/project_folder 中创建一个新的 htaccess 文件

  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. 将项目文件夹更改为您自己的文件夹


0
投票

注意项目路径大写。 即,如果 base_url 为

http://localhost/ci/
并且目录名称为
CI
,则可能不起作用。


0
投票

您可以在您的项目上创建一个 .htaccess 文件,例如:“your_project/[将 .htaccess 放在这里]。 记得将文件命名为 .htaccess,前面带点

然后就可以添加代码了

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

这段代码在我的项目中运行良好


-1
投票

我再次克隆了 git 存储库,并对灯进行了全新安装,现在它可以工作了。

© www.soinside.com 2019 - 2024. All rights reserved.