liangpz521 发表于 2012-6-29 11:10:48

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

添加了一个.htaccess 文件,内容是这样:
TEXT
RewriteEngine On
RewriteBase /p2v/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /p2v/index.php?/$1

复制代码


修改了 system/core/URI.php 文件的 _set_uri_string 函数和 _explode_segments 函数
PHP

    /**
   * Set the URI String
   *
   * @accesspublic
   * @param   string
   * @returnstring
   */
    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.
   *
   * @accessprivate
   * @returnvoid
   */
    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 文件?

liangpz521 发表于 2012-6-29 14:28:35

暂时没想到别的好的方法你有好的方法吗

浪迹天涯 发表于 2012-6-29 14:59:36

apache的rewrite是否开启?否则.htaccess里的路由规则是不起作用的

浪迹天涯 发表于 2012-6-29 15:01:51

最好不要去修改CI自身的代码,如果CI自带的一些类无法满足项目想需要,那么就扩展它的类来实现你的功能,否则当要升级CI 版本的时候就够你折腾的
页: [1]
查看完整版本: CI框架中设置成二级目录访问不了的问题(已解决) 解决方