duanluanhui8348 2017-10-16 09:41
浏览 76
已采纳

CodeIgniter初始设置404

I just recently started learning CodeIgniter and trying to setup my project in this structure:

Specification
Apache/2.4.27 (Win64) PHP/5.6.31.
Server: WAMP Server 3 Localhost setup
CodeIgniter 3.1.2

Directory
www/CI/firstci/******

So using this directory structure will give me a 404 error when I navigate to www/CI/firstci/

404 Page Not Found The page you requested was not found.

If i put my CodeIgniter higher up the root like this

Directory
www/firstci/******

It will work when I navigate to www/firstci/ and it will direct me to a welcome page.

So my question is how do I fix this routing/path problem? If possible explain why CodeIgniter behaves like this too?

  • 写回答

2条回答 默认 最新

  • duanfu9523 2017-10-22 08:07
    关注

    Ok i have found out that after i changed:

    routes.php

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

    TO

    $route['default_controller'] = 'pages/view';
    $route['(:any)'] = 'pages/view/$1';
    $route['404_override'] = '';
    $route['translate_uri_dashes'] = FALSE;
    

    Add a controller file called Pages.php

    class Pages extends CI_Controller {
        public function view($page = 'home') {
            if (!file_exists(APPPATH.'views/pages/'.$page.'.php')){
                show_404();
            }
    
            $data['title'] = ucfirst($page);
    
            $this->load->view('templates/header');
            $this->load->view('pages/'.$page, $data);
            $this->load->view('templates/footer');
        }
    }
    

    Also added .htaccess

    RewriteEngine on
    RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
    RewriteCond %(REQUEST_FILENAME) !-f
    RewriteCond %(REQUEST_FILENAME) !-d
    RewriteRule ^(.*)$ ./index.php/$1 [L]
    

    And added the relevant files to view folder organizing it to this structure:

    templates/header
    pages/'.$page, $data
    templates/footer
    

    It now works and is able to direct me to any php page

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行