【问题标题】:Codeigniter 3 Remove index.php ProblemsCodeigniter 3 删除 index.php 问题
【发布时间】:2013-12-08 18:58:07
【问题描述】:

我有一个使用 codeigniter 2.1.4 为客户开发的小项目,现在,他坚持要迁移到 codeigniter 3 DEV 版本。我知道这不是一个好主意,但... 我的问题是我无法从 url 中删除 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 上),重新配置.
谢谢!

【问题讨论】:

标签: php apache .htaccess codeigniter mod-rewrite


【解决方案1】:

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

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

删除 index.php 后的?

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        【解决方案4】:

        在您的 CI 项目的根目录上创建新的 .htaccess 文件并在那里添加您的代码。不要更改应用程序文件夹中的 .htaccess 文件。这对我有用

        【讨论】:

          【解决方案5】:

          只需下载 CI 版本2.2.0

          从根目录复制 .htaccesshtaccess.txt 并将其粘贴到您的 Codeigniter 3 项目中。

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

          【讨论】:

            【解决方案6】:

            我是这样弄的:

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

            【讨论】:

              【解决方案7】:
              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. 将项目文件夹更改为您自己的文件夹

              【讨论】:

                【解决方案8】:

                在 .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“;
                

                它会起作用的。

                【讨论】:

                  【解决方案9】:
                  1. 在您的项目根文件夹/Your_codeigniter_project_folder/.htacess 中创建一个.htacess 文件并粘贴此代码

                    重写引擎开启

                    RewriteCond %{REQUEST_FILENAME} !-f

                    RewriteCond %{REQUEST_FILENAME} !-d

                    重写规则 ^(.*)$ index.php/$1 [L]

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

                  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 modules/mod_rewrite.so

                  【讨论】:

                    【解决方案10】:

                    注意项目路径大写。 即如果base_url 是http://localhost/ci/ 并且目录名称是CI,它可能不起作用。

                    【讨论】:

                      猜你喜欢
                      • 2015-08-10
                      • 2015-09-28
                      • 2021-12-15
                      • 2020-07-08
                      • 2022-01-06
                      • 2016-01-16
                      • 1970-01-01
                      • 2011-07-09
                      • 1970-01-01
                      相关资源
                      最近更新 更多