hyshzy 发表于 2011-4-21 16:18:24

关于重定向的问题

现在我想将:http://localhost/wlbs/
http://localhost/wlbs/index.php

重定向到:

http://localhost/wlbs/index.php/defaults

以下是相关配置:(里面的www.126.com\www.163.com,为临时测试。重点是中间四行)。
不知道我这什么地方写错了?因为打开IE,输入http://localhost/wlbs/,没有重定向到我想要的。。。
望高手指教!!!!

RewriteEngine on
ErrorDocument 400 http://www.126.com/
ErrorDocument 404 http://www.163.com/

RewriteCond %{HTTP_HOST} ^wlbs/index.php$
RewriteRule ^(.*)$ http://localhost/wlbs/index.php/defaults/$1
RewriteRule http://localhost/wlbs/ http://localhost/wlbs/index.php/defaults/
RewriteRule http://localhost/wlbs/index.php http://localhost/wlbs/index.php/defaults/

RewriteRule ^/css/(.*.css$|.*.js$) gzip.php?$1
RewriteRule ^/js/(.*.css$|.*.js$) gzip.php?$1

rockics 发表于 2011-4-21 16:27:07

使用CI么?修改一下routes.php就可以了吧
当然你的apache也要配置成知道默认是index.php的

hyshzy 发表于 2011-4-21 16:30:48

apache配置:<IfModule dir_module>
    DirectoryIndex index.php index.htm index.html index.shtml
</IfModule>


LoadModule rewrite_module modules/mod_rewrite.so(已开启)

routes.php配置:
$route['default_controller'] = "defaults";
$route['404_override'] = '';

rockics 发表于 2011-4-21 16:38:52

apache配置:
    DirectoryIndex index.php index.htm index.html index.shtml

oadModule rewrite_mod ...
hyshzy 发表于 2011-4-21 16:30 http://codeigniter.org.cn/forums/images/common/back.gif测试表明是可以的,你的defaults控制器存在么
报什么错?

hyshzy 发表于 2011-4-21 16:54:56

!!!!!奇怪的问题!!!!

本帖最后由 hyshzy 于 2011-4-21 17:26 编辑

我在本地输入:http://localhost/wlbs/index.php/
http://localhost/wlbs/index.php/defaults
可以登录系统,登录后的地址是:
http://localhost/wlbs/index.php/main

但是,如果我输入的是
http://localhost/wlbs/
http://localhost/wlbs/index.php
系统就无法登录,出现错误的地址为:
http://localhost/wlbs/defaults?ref=%2Fmain    (明显没有了index.php)

这个问题岂不说,更郁闷的是以上可以正确登录系统的地址,只能在IE下登录(本机是IE8),在firefox,chrome下都登录不了,但是数据库有更新记录(就是登录成功后,要更新最后登录时间和登录次数的,这个是正常的。)。我通过firebug发现这样错误:
加载源代码失败: http://localhost/wlbs/index.php/main



也不知道是为什么会这样?? 初步判断和index.php是有关的,找了一天也没找到具体的问题所在。

以下是我的相关配置信息:

config.php文件:
$config['index_page'] = 'index.php';

defaults.htm里的form提交:
<form name="login" action="defaults?ref={my:$ref_token}" method="post">

defaults.php 相关代码 (为defaults.htm所对应的控制器)

    function __construct()
{

      parent::__construct();


      $this->load->library('smarty');

      $this->load->library('authcode'); //加载验证码类

      $this->load->library('login_auth');

      $this->load->library('form_validation');

      $this->load->model('users_model', 'users');



$this->_check_referrer();
}


private function _check_referrer()
{

      $ref = $this->input->get('ref', TRUE);

      $this->referrer = (!empty($ref)) ? $ref : '/main';

      $this->smarty->assign('ref_token',urlencode($this->referrer));
}


public function index()
{
      // 判断是否登录

      if($this->login_auth->hasLogin())

      {

          redirect($this->referrer);

      }

      …………

   if(!empty($user))

   {
            if($this->login_auth->process_login($user))   //如果用户存在,更新相关操作,然后跳转到内页
            {
                      redirect($this->referrer);      //登录成功跳到的页面:http://localhost/wlbs/index.php/main
            }
    }


注:system/core/Config里的site_url(),最后一行 是:
return $this->slash_item('base_url').$this->item('index_page').'?'.$uri;
结果一直导致我的浏览登录后地址变成:
http://localhost/wlbs/index.php?/main, 结果导致:URL错误。
所有我改成了:


function site_url($uri = '')
{
      if (is_array($uri))
      {
            $uri = implode('/', $uri);
      }

      if ($uri == '')
      {
            return $this->slash_item('base_url').$this->item('index_page');
      }
      else
      {
            $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
            return $this->slash_item('base_url').$this->slash_item('index_page').trim($uri, '/').$suffix;
      }
}




(本人的系统结构采用的是CI 2.0.2 + smarty 3.0.7结合的。没有application文件夹,application文件夹里的所有目录和system同处于一个根目录里面,)

hyshzy 发表于 2011-4-21 16:56:54

回复 4# rockics


   控制器存在啊。。。没报错哦。。。就是没反应。。敲入http://localhost/wlbs/能打开的。。我输入 http://localhost/wlbs/index.php/ 在IE下是可以登录的

Hex 发表于 2011-4-21 17:12:09

用 URI 路由,URI 路由和 url rewrite 没关系。
先看看手册,你这个用路由 1分钟解决

baiyuxiong 发表于 2011-4-21 17:15:53

代码用编辑器的功能格式化一下,太乱了。

hyshzy 发表于 2011-4-21 17:26:48

回复 2# baiyuxiong


   好了。。格式化过了。。烦请指教!

rockics 发表于 2011-4-21 19:40:02

还是把你那几条重写规则去了吧呵呵
页: [1] 2
查看完整版本: 关于重定向的问题