【问题标题】:codeigniter redirect function puts ? between base_url and controller/functioncodeigniter 重定向功能?在 base_url 和控制器/函数之间
【发布时间】:2013-03-12 06:03:10
【问题描述】:

我制作了一个登录脚本来访问另一个控制器,这样其他人就看不到了。

现在我的控制器中有一个重定向功能,可以重定向到另一个控制器。

现在当我重定向它时它工作正常,但它放了一个 ?我的 base_url 和控制器之间是这样的:

http://kees.een-site-bouwen.nl/?/member/index

我该如何解决?

我家的控制器功能:

public function process(){
    // Load the model
    $this->load->model('login_model');
    // Validate the user can login
    $result = $this->login_model->validate();
    // Now we verify the result
    if(! $result){
        // If user did not validate, then show them login page again
        $msg = '<font color=red>Invalid username and/or password.</font><br />';
        $this->index($msg);
    }else{
        // If user did validate, 
        // Send them to members area
        redirect('/member/index');
    }        
}  

这与我的 .htaccess 文件有关吗?

看起来像这样:

<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
 ErrorDocument 404 index.php
</IfModule>

【问题讨论】:

    标签: php codeigniter url redirect


    【解决方案1】:

    使用redirect('member/index') insted of redirect('/member/index')

    【讨论】:

      【解决方案2】:

      将您的 htaccess 更改为:

      <IfModule mod_rewrite.c>
      RewriteEngine On
      
      RewriteCond %{REQUEST_URI} ^system.*
      RewriteRule ^(.*)$ index.php/$1 [L]
      
      RewriteCond %{REQUEST_URI} ^LoginTut.*
      RewriteRule ^(.*)$ index.php/$1 [L]
      
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php/$1 [L]
      </IfModule>
      

      这样 url 被解析为 index.php/controller 而不是 index.php?/controller

      【讨论】:

      • 你介意更详细而不是粗鲁吗?
      【解决方案3】:

      我通过像这样禁用 query_strings 来解决它:

      发件人:

      $config['enable_query_strings'] = TRUE;
      

      收件人:

      $config['enable_query_strings'] = FALSE;
      

      在我的 Config.php 文件中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-04-04
        • 1970-01-01
        • 1970-01-01
        • 2012-07-16
        • 1970-01-01
        • 1970-01-01
        • 2021-07-25
        相关资源
        最近更新 更多