无限重定向循环


Infinite redirect loop

我必须完成别人的项目,但我有一个无效请求的问题:

如果我输入这个url,它可以工作:

http://localhost/Files/pictures/thumbs/28967579qwR.jpg_2014-03-11%2014-13-53.jpg

对于这个,我有无限循环(文件不存在):

http://localhost/Files/pictures/thumbs/s28967579qwR.jpg_2014-03-11%2014-13-53.jpg

对于这个,我没有重定向循环,但我要求一个不存在的文件:

http://localhost/home/sd.jpg

在。htaccess中有:

Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]

我的index.php文件:

<?php
/*
 * Url friendly base
 */
$url = $_SERVER['REQUEST_URI'];
error_log($url);
if (isset($url)) {
    $links = explode('/', $url);
    //voler minuscula
    $link = strtolower($links[1]);
    switch ($link) {
        case 'join':
            include_once 'frontend/join.php';
            break;
        case 'join-video':
            include_once 'frontend/join-video.php';
            break;
        case 'hd-movies':
            include_once 'frontend/hd-movies.php';
            break;
        case 'contact':
            include_once 'frontend/contact.php';
            break;
        case 'login':
            include_once 'frontend/login.php';
            break;
        case 'model':
            include_once 'frontend/model.php';
            break;
        case 'our-models':
            include_once 'frontend/our-models.php';
            break;
        case 'recherche':
            include_once 'frontend/resultat-recherche.php';
            break;
        case 'video':
            include_once 'frontend/video.php';
            break;
        case 'update':
            include_once 'frontend/updates.php';
            break;
        case 'home':
            include_once 'frontend/index.php';
            break;
        default:
            header('Location: home/');
            // include_once 'frontend/index.php';
            break;
    }
}
?>

你知道为什么这种情况发生在一些文件上而不是其他文件上以及如何修复它吗?谢谢。

为了避免无限循环,我最终决定在这里使用会话:

    <?php
session_start();
if (!isset($_SESSION['redirect_uri'])) {
    $_SESSION['redirect_uri'] = 0;
}
$url = $_SERVER['REQUEST_URI'];
if (isset($url)) {
$links = explode('/', $url);
//voler minuscula
$link = strtolower($links[1]);
switch ($link) {
    case 'join':
        include_once 'frontend/join.php';
        break;
    case 'join-video':
        include_once 'frontend/join-video.php';
        break;
    case 'hd-movies':
        include_once 'frontend/hd-movies.php';
        break;
    case 'contact':
        include_once 'frontend/contact.php';
        break;
    case 'login':
        include_once 'frontend/login.php';
        break;
    case 'model':
        include_once 'frontend/model.php';
        break;
    case 'our-models':
        include_once 'frontend/our-models.php';
        break;
    case 'recherche':
        include_once 'frontend/resultat-recherche.php';
        break;
    case 'video':
        include_once 'frontend/video.php';
        break;
    case 'update':
        include_once 'frontend/updates.php';
        break;
    case 'home':
        include_once 'frontend/index.php';
        break;
    default:
        // This will avoid redirect loop
        $_SESSION['redirect_uri']++;
        if ($_SESSION['redirect_uri'] < 1 ) {
            header('Location: home/');
        } else {
            $_SESSION['redirect_uri'] = 0;
            header("HTTP/1.0 404 Not Found");
        }
        break;
}

}div ?>