【问题标题】:Codeigniter 3 routing errorCodeigniter 3 路由错误
【发布时间】:2017-01-02 20:04:16
【问题描述】:

我在 codeigniter 3 上遇到路由错误。

未找到 在此服务器上未找到请求的 URL /index.php。 Apache/2.4.7 (Ubuntu) 服务器

我做了什么。 我的.htaccess

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

同时设置AllowOverride ALL

我的控制器Test.php

class Test extends CI_Controller {
    public function index(){
        print_r('test');
        die();
    }
}

我的路线:$route['test/(:any)'] = 'test/$1';

并尝试通过 url 到达此页面:

http://localhost/codeigniter/test/index.php
http://localhost/codeigniter/test/

【问题讨论】:

    标签: codeigniter-3


    【解决方案1】:

    试试这个.htaccess

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

    如果您要访问控制器,只需键入(假设 codeigniter 作为您的项目文件夹名称)

    http://localhost/codeigniter/test/
    

    这个$route['test/(:any)'] = 'test/$1';的原因是什么?

    this 指定将有参数传递给 this。它可以是数字或字母。例如http://localhost/codeigniter/test/aaahttp://localhost/codeigniter/test/25


    Look at this

    【讨论】:

      【解决方案2】:

      您的问题是,当您尝试使用此路由codeigniter/test/1 时,您传递 uri(2), uri(2) 是为控制器的方法设计的,您应该首先指定您的方法,所以它就像这样$route['test/(any)'] = 'test/index/$i'; btw codeigniter 被视为您的 uri(0)。

      【讨论】:

        猜你喜欢
        • 2019-07-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-06
        • 2015-06-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多