Home Redirect too many times! Codeigniter
Reply: 0

Redirect too many times! Codeigniter

Esar-ul-haq Qasmi
1#
Esar-ul-haq Qasmi Published in 2018-01-09 07:13:38Z

In a Multilingual website the URLs look like this http://localhost/mysite/en/about. This works fine upto single level of URL redirection.

But when i try to make these URLs SEO friendly http://localhost/mysite/en/about/about-childs, it redirects to same page too many times and never comes on destination. I am unable to find the cause.

I am using redirect($slug->language_slug.'/about/about-childs','refresh');

And here is the redirect helper function

function redirect($uri = '', $method = 'auto', $code = NULL)
{
    if ( ! preg_match('#^(\w+:)?//#i', $uri))
    {
        $uri = site_url($uri);
    }

    // IIS environment likely? Use 'refresh' for better compatibility
    if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE)
    {
        $method = 'refresh';
    }
    elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code)))
    {
        if (isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD']) && $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1')
        {
            $code = ($_SERVER['REQUEST_METHOD'] !== 'GET')
                ? 303   // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get
                : 307;
        }
        else
        {
            $code = 302;
        }
    }

    switch ($method)
    {
        case 'refresh':
            header('Refresh:0;url='.$uri);
            break;
        default:
            header('Location: '.$uri, TRUE, $code);
            break;
    }
    exit;
}

}

Here is my routs.php file code, and it comes into else part where it returns controller function return 'findcontent/index'; which contains my redirect functionality redirect($slug->language_slug.'/about/about-childs','refresh');

    $route['^(\w{2})/(.*)'] = function($language, $link) use ($controllers_methods)
{
    if(array_key_exists($language,$controllers_methods))
    {
        foreach ($controllers_methods[$language] as $key => $sym_link) {
            if (strrpos($link, $key, 0) !== FALSE) {
                $new_link = ltrim($link, $key);
                $new_link = $sym_link . $new_link;
                return $new_link;
            }
            else
            {
                return 'findcontent/index';
            }
        }
    }
    else
    {
        return $link;
    }
};
$route['^(\w{2})$'] = $route['default_controller'];

Here is htaccess

RewriteEngine On
SetEnvIf Host www.yoursite.tld$ CI_ENV=production
#SetEnvIf Host test.yoursite.tld$ CI_ENV=testing
SetEnvIf Host localhost$ CI_ENV=development

RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.338882 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO