用户
 找回密码
 入住 CI 中国社区
搜索
查看: 5488|回复: 5
收起左侧

CI放在二级路径下面,URL下面带二级目录的时候全部页面404

[复制链接]
发表于 2012-3-29 11:20:25 | 显示全部楼层 |阅读模式
如题
我用的xmapp,CI是2.1.0

CI放在了xmapp下面的 codeigniter_210 目录里,所以URL里面就带上了 http://localhost/codeigniter_210/ 二级目录。但是这个二级目录会被解释成控制器 codeigniter_210 ,很明显没有这个控制器,所以访问任何页面程序都返回404

请问,CI 是不是不支持这种二级目录的形式?有没有地方可以设置?
我已经设置过
$config['base_url']        = 'http://localhost/codeigniter_210/';
但是没有用处。
发表于 2012-3-29 12:09:04 | 显示全部楼层
检查你的.htaccess的配置
 楼主| 发表于 2012-3-29 12:49:01 | 显示全部楼层
没有这个文件。。。
需要添加一个吗?要怎么设置呢?
请教~
 楼主| 发表于 2012-3-29 15:12:33 | 显示全部楼层
添加了一个.htaccess 文件,内容是这样:

  1. RewriteEngine On
  2. RewriteBase /CodeIgniter_2.1.0_1/
  3. RewriteCond %{REQUEST_FILENAME} !-f
  4. RewriteCond %{REQUEST_FILENAME} !-d
  5. RewriteRule ^(.*)$ /CodeIgniter_2.1.0_1/index.php?/$1 [L]

复制代码


修改了 system/core/URI.php 文件的 _set_uri_string 函数和 _explode_segments 函数
PHP复制代码
 
    /**
     * Set the URI String
     *
     * @access  public
     * @param   string
     * @return  string
     */

    function _set_uri_string($str) {
        if ($this->config->item("base_folder")) {
            if ($str == $this->config->item("base_folder")) {
                $str = "";
            }
        }
 
        // Filter out control characters        
        $str = remove_invisible_characters($str, FALSE);
 
        // If the URI contains only a slash we'll kill it
        $this->uri_string = ($str == '/') ? '' : $str;
    }
 
 
    /**
     * Explode the URI Segments. The individual segments will
     * be stored in the $this->segments array.
     *
     * @access  private
     * @return  void
     */

    function _explode_segments() {
        $is_ignored = FALSE;
        foreach (explode("/", preg_replace("|/*(.+?)/*$|", "\\1", $this->uri_string)) as $val) {
            // Filter segments for security
            $val = trim($this->_filter_uri($val));
 
            if ($val != '') {
                if (!$is_ignored && $this->config->item("base_folder")) {
                    if ($val == $this->config->item("base_folder")) {
                        $is_ignored = TRUE;
                        continue;
                    }
                }
                $this->segments[] = $val;
            }
        }
    }
 
 
复制代码


在 application/config/config.php 里面增加了配置:
PHP复制代码
 
$config['base_folder']  = 'CodeIgniter_2.1.0_1';
 
复制代码


OK,现在就可以运行了。
发表于 2012-6-29 11:05:20 | 显示全部楼层
很不错的 谢谢楼主分享了 刚在做项目 也遇到这个问题了
发表于 2012-6-29 23:44:42 | 显示全部楼层
hnzksq 发表于 2012-3-29 15:12
添加了一个.htaccess 文件,内容是这样:

这是下下策啊,最基本的原则就是不要去修改CI自身的代码,除非别无他法来满足项目的需求。
这个问题很显然是 url重写上没配置好的原因所导致的问题了。
1、rewrite模块开启,2、.htaccess文件里规则的写法,3、application/config/config.php中$config['index_page']的值

本版积分规则