[英].htaccess and php redirect causing loop
Hey I searched all of the related questions and I didn't find any solution for my case. 嘿,我搜索了所有相关问题,但没有找到解决方案。
I have a script with urls like the following: 我有一个网址如下的脚本:
htt://www.example.com/index.php/dosomthing/parametrs
Now I used this: 现在我用这个:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Then in my default controller I check if the user is logged in or not, if not I redirect it to the login controller using this class function: 然后在我的默认控制器中,我检查用户是否已登录,如果不是,则使用此类函数将其重定向到登录控制器:
function redirect($uri = '', $method = 'location', $http_response_code = 302)
{
$uri = $this->config['home_url'] . ltrim($uri, '/');
switch($method)
{
case 'refresh' : header("Refresh:0;url=".$uri);
break;
default : header("Location: ".$uri, TRUE, $http_response_code);
break;
}
$this->dija = null;
exit;
}
It works on localhost but on the hosting it doesn't work and causes redirect loop, I'm really frustrated don't know what to do. 它可以在localhost上运行,但是在主机上却无法正常工作,并且会导致重定向循环,我真的很沮丧,不知道该怎么办。
Change your RewriteRule to: 将您的RewriteRule更改为:
RewriteRule ^(.*)$ index.php?$1 [L]
In the old case you're always rewriting to the same old url, and just prepending the index.php part once more, because there is no file that's named "index.php/" 在旧的情况下,您总是要重写到相同的旧url,并再次在index.php部分之前添加前缀,因为没有文件名为“ index.php /”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.