簡體   English   中英

.htaccess和php重定向導致循環

[英].htaccess and php redirect causing loop

嘿,我搜索了所有相關問題,但沒有找到解決方案。

我有一個網址如下的腳本:

htt://www.example.com/index.php/dosomthing/parametrs

現在我用這個:

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

然后在我的默認控制器中,我檢查用戶是否已登錄,如果不是,則使用此類函數將其重定向到登錄控制器:

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;
    }

它可以在localhost上運行,但是在主機上卻無法正常工作,並且會導致重定向循環,我真的很沮喪,不知道該怎么辦。

將您的RewriteRule更改為:

RewriteRule ^(.*)$ index.php?$1 [L]

在舊的情況下,您總是要重寫到相同的舊url,並再次在index.php部分之前添加前綴,因為沒有文件名為“ index.php /”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM