【问题标题】:Codeigniter cannot access controller without index.phpCodeigniter 无法访问没有 index.php 的控制器
【发布时间】:2019-02-05 06:31:46
【问题描述】:

我的本​​地 xampp codeigniter 项目的 url 是 http://localhost/ci_yudeesh/index.php 但后来想从 url 中删除 index.php 部分,所以我按照用户指南中给出的步骤操作。

之后我可以在没有 index.php 的情况下使用 url 访问项目 http://localhost/ci_yudeesh/

我有一个名为 Home 的控制器,我可以使用 http://localhost/ci_yudeesh/index.php/home 访问它 ,但是当尝试使用http://localhost/ci_yudeesh/home 访问它时会出现此错误:

这是我的配置:

$config['base_url'] = 'http://localhost/ci_yudeesh/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

这是我的 .htaccess:

<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

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

这是我的路线:

$route['default_controller'] = 'Home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

有人可以帮我解决这个问题吗?我尝试了类似类型问题的所有其他答案,但都没有奏效。

【问题讨论】:

    标签: php .htaccess codeigniter codeigniter-3


    【解决方案1】:

    更改 .htaccess 文件。从现有文件中删除代码并在文件中添加以下代码:-

    重写引擎开启

    RewriteCond $1 !^(index.php|resources|robots.txt)

    RewriteBase /ci_yudeesh/

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

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

    【讨论】:

      【解决方案2】:

      从 application 文件夹中删除 .htaccess 并将其放在应用程序文件夹之外,并且只在其中编写以下代码。如果它不起作用,那么我会给你另一个 .htaccess 代码。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-01
        • 2021-12-08
        • 2016-06-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多