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

[HELP] 关于重定向的问题

[复制链接]
发表于 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$ [NC]
RewriteRule ^(.*)$ http://localhost/wlbs/index.php/defaults/$1 [R=301,L]
RewriteRule http://localhost/wlbs/ http://localhost/wlbs/index.php/defaults/ [R=301,L]
RewriteRule http://localhost/wlbs/index.php http://localhost/wlbs/index.php/defaults/ [R=301,L]

RewriteRule ^/css/(.*.css$|.*.js$) gzip.php?$1 [L]
RewriteRule ^/js/(.*.css$|.*.js$) gzip.php?$1 [L]
发表于 2011-4-21 16:27:07 | 显示全部楼层
使用CI么?修改一下routes.php就可以了吧
当然你的apache也要配置成知道默认是index.php的
 楼主| 发表于 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'] = '';
发表于 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
测试表明是可以的,你的defaults控制器存在么  
报什么错?
 楼主| 发表于 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
2.png


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

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

config.php文件:
PHP复制代码
$config['index_page'] = 'index.php';
复制代码


defaults.htm里的form提交:
HTML复制代码
<form name="login" action="defaults?ref={myref_token}" method="post">
复制代码


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

PHP复制代码
    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');
 
[b]
 
$this->_check_referrer();[/b]
}
 
 
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错误。
所有我改成了:

PHP复制代码
 
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同处于一个根目录里面,)
8.jpg
 楼主| 发表于 2011-4-21 16:56:54 | 显示全部楼层
回复 4# rockics


   控制器存在啊。。。没报错哦。。。就是没反应。。敲入http://localhost/wlbs/能打开的。。我输入 http://localhost/wlbs/index.php/ 在IE下是可以登录的
发表于 2011-4-21 17:12:09 | 显示全部楼层
用 URI 路由,URI 路由和 url rewrite 没关系。
先看看手册,你这个用路由 1分钟解决
发表于 2011-4-21 17:15:53 | 显示全部楼层
代码用编辑器的功能格式化一下,太乱了。
 楼主| 发表于 2011-4-21 17:26:48 | 显示全部楼层
回复 2# baiyuxiong


   好了。。格式化过了。。烦请指教!
发表于 2011-4-21 19:40:02 | 显示全部楼层
还是把你那几条重写规则去了吧  呵呵

本版积分规则