使用 CodeIgniter 重定向 [英] Redirect with CodeIgniter

查看:31
本文介绍了使用 CodeIgniter 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我为什么我的重定向助手不能像我期望的那样工作?我正在尝试重定向到我的主控制器的 index 方法,但是当它应该路由到 www.mysite.com/时它需要我 www.mysite.com/index/provider1/provider1.这对任何人都有意义吗?我将配置中的索引页设置为空白,尽管我不认为这是问题所在.有没有人有关于如何解决这个问题的建议?提前致谢!

Can anyone tell me why my redirect helper does not work the way I'd expect it to? I'm trying to redirect to the index method of my main controller, but it takes me www.mysite.com/index/provider1/ when it should route to www.mysite.com/provider1. Does this make sense to anyone? I have index page in config set to blank, although I don't think that it is the issue. Does anyone have advice on how to fix this issue? Thanks in advance!

控制器:

if($provider == '') {
    redirect('/index/provider1/', 'location');
}

.htaccess:

RewriteEngine on

RewriteCond %{REQUEST_URI} !^(index.php|files|images|js|css|robots.txt|favicon.ico)

RewriteCond %{HTTP_HOST} ^mysite.com/ttnf/
RewriteRule (.*) http://www.mysite.com/ttnf/$1 [R=301,L]

RewriteBase /ttnf/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

php_flag display_errors On

推荐答案

redirect()

网址助手


代码点火器中的重定向语句使用重定向头语句将用户发送到指定的网页.

redirect()

URL Helper


The redirect statement in code igniter sends the user to the specified web page using a redirect header statement.

该语句驻留在 URL 帮助器中,它以下列方式加载:

This statement resides in the URL helper which is loaded in the following way:

$this->load->helper('url');

重定向函数加载在函数调用的第一个参数中指定的本地 URI,并使用配置文件中指定的选项构建.

The redirect function loads a local URI specified in the first parameter of the function call and built using the options specified in your config file.

第二个参数允许开发者使用不同的 HTTP 命令来执行重定向位置"或刷新".

The second parameter allows the developer to use different HTTP commands to perform the redirect "location" or "refresh".

根据 Code Igniter 文档:定位速度更快,但在 Windows 服务器上有时会出现问题."

According to the Code Igniter documentation: "Location is faster, but on Windows servers it can sometimes be a problem."

示例:

if ($user_logged_in === FALSE)
{
     redirect('/account/login', 'refresh');
}

这篇关于使用 CodeIgniter 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆