使用CodeIgniter重定向 [英] Redirect with CodeIgniter
问题描述
任何人都可以告诉我为什么我的重定向助手不工作,我期望它的方式?我试图重定向到我的主控制器的索引方法,但它需要我 www.mysite.com/index/provider1 /
当它应该路由到 www.mysite.com/provider1
。这对任何人都有意义吗?我有配置中的索引页设置为空白,虽然我不认为这是问题。有人有如何解决这个问题的建议吗?先感谢!
控制器:
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在
redirect()
网址助手
代码igniter中的重定向语句使用重定向头语句将用户发送到指定的网页。
此语句位于URL helper('url');
$ this->
重定向函数加载在函数调用的第一个参数中指定的本地URI,
第二个参数允许开发人员使用不同的HTTP命令来执行重定向location或refresh。
根据Code Igniter文档:位置更快,但在Windows服务器上它有时可能是一个问题。例如:
if($ user_logged_in === FALSE)
{
redirect('/ account / login','refresh');
}
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!
Controller:
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()
URL Helper
The redirect statement in code igniter sends the user to the specified web page using a redirect header statement.
This statement resides in the URL helper which is loaded in the following way:
$this->load->helper('url');
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.
The second parameter allows the developer to use different HTTP commands to perform the redirect "location" or "refresh".
According to the Code Igniter documentation: "Location is faster, but on Windows servers it can sometimes be a problem."
Example:
if ($user_logged_in === FALSE)
{
redirect('/account/login', 'refresh');
}
这篇关于使用CodeIgniter重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!