【问题标题】:Remove index.php from codeigniter url从 codeigniter url 中删除 index.php
【发布时间】:2012-06-15 02:06:04
【问题描述】:

我是 codeigniter 的新手。我在 localhost/path/learn_ci 安装了我的 codeigniter。

我已按照 codeigniter wiki 中给出的所有步骤进行操作。这是我的 .htaccess 文件。

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

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

我还根据需要更改了配置文件。但是当我尝试访问

我收到此错误

“在此服务器上找不到请求的 URL /learn_ci/index.php/welcome”

我已经仔细检查了...... Apache 中的 mod_rewrite 模块已打开。

RewriteBase 解决方案也不起作用。我是不是做错了什么??

【问题讨论】:

    标签: php .htaccess codeigniter


    【解决方案1】:

    正如其他人所说,确保在您的 apache 配置或虚拟主机文件中将 AllowOverride 设置为 All。 鉴于您设置了 codeigniter 的路径,您的 htaccess 应该如下所示:

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

    另外,请记住,您正在使用的任何资产(img、css、js 等)都是通过 base_url() 函数或使用相对路径引用的。您项目的根目录将是 /path/learn_ci。

    我发现创建一个虚拟主机并在本地向我的主机文件添加一个条目更容易。这更好地模仿了现实生活。

    【讨论】:

    【解决方案2】:

    试试:

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

    【讨论】:

      【解决方案3】:

      您可以执行以下操作:

      config.php 文件集中的第一个

      $config['index_page'] = '';
      

      接下来,在codeigniter根文件夹中创建一个.htaccess文件,添加如下内容:

      RewriteEngine on
      RewriteCond $1 !^(index\.php|public|\.txt)
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?$1
      

      保存文件。它应该可以工作。

      【讨论】:

        【解决方案4】:

        您将 htaccess 文件放在与 index.php 相同的目录下的根 public_html 文件夹中

        然后从您的 htaccess 文件中删除 /learn_ci,只需将其设为 /index.php/$1

        【讨论】:

          【解决方案5】:

          检查你的 apache 配置,应该是这样的:

          Options Indexes FollowSymLinks MultiViews
          AllowOverride all
          Order allow,deny
          allow from all
          

          【讨论】:

            【解决方案6】:

            我想添加我的答案。我的项目基本网址是http://localhost/newproject/ 我在 newproject 文件夹中包含了 htacess 文件。

            这里是代码。

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

            然后我更改配置文件。

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

            一切都开始起作用了。现在不再有 index.php 文件了。

            【讨论】:

            • 你应该启用 Apache 模块模块重写
            猜你喜欢
            • 2016-05-14
            • 2014-10-28
            • 2012-09-21
            • 2011-10-12
            • 2017-07-16
            • 2014-02-28
            • 1970-01-01
            相关资源
            最近更新 更多