CodeIgniter3 中的 URL 路由不会到达正确的目录

问题描述 投票:0回答:1

我刚刚下载了 CI,并将 2 个文件夹应用程序和系统复制到我的 web 文件夹中。

我将index.php移至应用程序内部,并且修改了.htaccess

我的网络文件夹是

C:\onedrive\dropbox\template\
我的访问网址是
http://localhost/template/application/index.php

每次我打开

http://localhost/template/application/
,它总是说:

404 Page Not Found,您请求的页面未找到。

当我用

var_dump($RTR->class);
调试 CodeIgniter.php 时,我得到:

'template'

这就是为什么我的网址总是错误的。为什么会出现这种情况?

我刚刚修改了第一行“_set_request”方法中的“Router.php”,以排除我的 URL 进行分段:

// akhyar : exclude url before index.php first
$excSegment = explode('/',config_item('base_url'));
$segments = array_diff($segments,array('index.php'));
foreach ($excSegment as $idxSegment => $valSegment) {
    $segments = array_values(array_diff($segments,array(urlencode($valSegment))));
}

变成:

protected function _set_request($segments = array())
{
    // akhyar : exclude url before index.php first
    $excSegment = explode('/',config_item('base_url'));
    $segments = array_diff($segments,array('index.php'));
    foreach ($excSegment as $idxSegment => $valSegment) {
        $segments = Array_values(
            array_diff(
                $segments,
                array(urlencode($valSegment))
            )
        );
    }
    $segments = $this->_validate_request($segments);
    ...........
}
php codeigniter codeigniter-3 url-routing
1个回答
0
投票

config/routes.php

$route['default_controller'] = "Your_controller";

并且在控制器文件名中应该是(例如主文件)使用

main.php

内置控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

    class Main extends CI_Controller
    {

    }
© www.soinside.com 2019 - 2024. All rights reserved.