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

CI框架中设置成二级目录访问不了的问题(已解决) 解决方

[复制链接]
发表于 2012-6-29 11:10:48 | 显示全部楼层 |阅读模式
添加了一个.htaccess 文件,内容是这样:
TEXT
RewriteEngine On
RewriteBase /p2v/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /p2v/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']  = 'p2v'; 这个要新增加的
$config['base_url']  = 'http://www.58xxw.com/p2v/';  这个配置文件中有的 只用修改成二级的就可以了


复制代码


发表于 2012-6-29 12:22:17 | 显示全部楼层
为什么还需要去修改system/core/URI.php 文件?
 楼主| 发表于 2012-6-29 14:28:35 | 显示全部楼层
暂时没想到别的好的方法  你有好的方法吗
发表于 2012-6-29 14:59:36 | 显示全部楼层
apache的rewrite是否开启?否则.htaccess里的路由规则是不起作用的
发表于 2012-6-29 15:01:51 | 显示全部楼层
最好不要去修改CI自身的代码,如果CI自带的一些类无法满足项目想需要,那么就扩展它的类来实现你的功能,否则当要升级CI 版本的时候就够你折腾的

本版积分规则