dongzhi4470 2016-01-16 09:10
浏览 56
已采纳

Codeigniter路由为静态页面主页工作其他路由而不是页面

When I access localhost:8080/ignite_me it shows me contents of home.php with header and footer but when I try localhost:8080/igniteme/test It gives me Apche 404 page and test.php exist in my views/pages where i have put my home.php

even localhost:8080/igniteme/home is not working but localhost:8080/igniteme shows content of home.php

routes.php

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

Pages.php

<?php
class Pages extends CI_Controller {

    public function _construct()
    {
        parent::_construct();
    }

        public function view($page = 'home')
        {
            if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php'))
            {
                // Whoops, we don't have a page for that!
                show_404();
            }

            $data['title'] = ucfirst($page); // Capitalize the first letter



            $this->load->view('templates/header', $data);
            $this->load->view('pages/'.$page, $data);
            $this->load->view('templates/footer', $data);
        }
}

.htaccess

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

config.php

$config['base_url'] = 'http://localhost:8080/igniteme/';
$config['index_page'] = '';

I am unable to understand why home.php works with localhost:8080/ignite_me and why not with localhost:8080/igniteme/home or any other page is not working I have copied .htaccess from some other stack overflow question it was not working even with default one.

here is link to my complete codeignite folder igniteme

  • 写回答

4条回答 默认 最新

  • dongmang3961 2016-01-16 10:45
    关注

    I am using wamp I use this htaccess below

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

    Make sure in main directory.

    Also in wamp make sure YOU HAVE ENABLED APACHE MOD REWRITE

    Scroll/click and go down the list to you find rewrite_module click on it then go and restart wamp.

    enter image description here

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

报告相同问题?

悬赏问题

  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,