【问题标题】:Removing index.php in Codeigniter 3 apache2 server删除 Codeigniter 3 apache2 服务器中的 index.php
【发布时间】:2018-01-27 22:33:53
【问题描述】:

我正在 Kali Linux 中使用 Code Igniter,我已经按照文档中的说明配置了 .htaccess 文件并正确配置了文件,但是如果没有 index.php,它就无法工作

a2enmod rewrite

我还启用了重写模式并重新启动了 apache。这是我的 .htaccess 文件

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

【问题讨论】:

  • 你在 $config['index_page'] 的 config.php 中删除了“index.php”吗?
  • like $config['index_page'] = "";
  • @Gopalakrishnan 是的,我做到了,但仍然是同样的问题!
  • 下面的答案肯定对你有帮助。如果不检查其他代码

标签: php apache .htaccess codeigniter url


【解决方案1】:

在 config.php 中

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

在您的项目位置创建包含以下内容的 .htaccess 文件 (例如:/var/www/html/yourproject 在“yourproject”文件夹中创建 .htaccess)

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

将以下内容添加到您的虚拟主机配置文件中

<Directory "/var/www/html/yourproject">
            Options All
            AllowOverride All
            Allow from all
</Directorey>

然后重启apache

【讨论】:

    【解决方案2】:

    按照此步骤从 url 中删除 index.php

    1)从config.php文件中删除“index.php”

    $config['index_page'] = "";
    

    2) 你的 .htaccess 文件应该是:

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

    3)在某些情况下,您还必须在配置文件中进行更改

    //find the below code
    $config['uri_protocol'] = "AUTO"
    //replace with the below code
    $config['uri_protocol'] = "REQUEST_URI" 
    

    【讨论】:

    • 是的,但我还是遇到了同样的问题!
    • Codeigniter 3 及以上版本没有 AUTO
    • 你在根目录添加.htaccess文件了吗?
    【解决方案3】:

    只需在您的 .htaccess 文件中使用它

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

    【讨论】:

      猜你喜欢
      • 2014-11-25
      • 2013-09-04
      • 2022-01-06
      • 2015-09-28
      • 2020-07-08
      • 2013-12-08
      • 2013-07-31
      • 2014-01-07
      • 2015-03-11
      相关资源
      最近更新 更多