Joomla网站正在获得303重定向循环

时间:2014-04-24 17:58:13

标签: redirect joomla

我的网站有时会在主页上获得303重定向循环。这在尝试查看网站“网页有重定向循环”时给出了错误,但大部分时间都是正常的。但是,303重定向对SEO来说并不好看。我正在使用Zo2框架运行Joomla 3.2.3。我使用了firefox live http header工具,这就是它显示的内容:

HTTP/1.1 303 See other
Date: Sat, 19 Apr 2014 06:42:44 GMT
Server: Apache mod_fcgid/2.3.10-dev
X-Powered-By: PHP/5.4.26
Set-Cookie: 81f5073a1f9d10dc244e07c98216335e=hb7mb5k3v0vftstcgtdbonikq6; path=/;         HttpOnly
Location: /
Cache-Control: max-age=600
Expires: Sat, 19 Apr 2014 06:52:44 GMT
Content-Length: 0
Keep-Alive: timeout=5
Connection: Keep-Alive

我一次经历并禁用Joomla中的每个插件,当我禁用Zo2框架插件时,303重定向消失了。我在他们的论坛上问过他们无法帮助我。所以,我搜索了zo2插件目录中的所有文件中的redirect一词,这就是我找到的。

这两个位于site.megamenu.js

!function ($) {
    $(document).ready(function ($) {
        // when clicking on menu
        redirect();
        var duration = 0;
        var $parent = $('.zo2-megamenu');
        var hover_type = $parent.data('hover');
        if ($parent.data('duration')) {
            duration = $parent.data('duration');
        }

function redirect() {
    $('.dropdown-toggle').on('click',function(e){
        if($(this).parent().hasClass('open') && this.href && this.href != '#'){
            window.location.href = this.href;
            e.preventDefault();
        }
    });
}

我使用相同的.htaccess和php.ini文件在此服务器上运行其他网站,所以我认为这不是问题,因为他们没有获得重定向。我将不胜感激。该网站为http://www.betterfreestuff.com

/**
 * Zo2 Framework (http://zo2framework.org)
 *
 * @link     http://github.com/aploss/zo2
 * @package  Zo2
 * @author   Hiepvu
 * @copyright  Copyright ( c ) 2008 - 2013 APL Solutions
 * @license  http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
 */

!function ($) {
    $(document).ready(function ($) {
        // when clicking on menu
        redirect();
        var duration = 0;
        var $parent = $('.zo2-megamenu');
        var hover_type = $parent.data('hover');
        if ($parent.data('duration')) {
            duration = $parent.data('duration');
        }

        if (duration && (hover_type == 'hover')) {
            var timeout = duration ? duration + 50 : 500;
            $('.nav > li, li.mega').hover(
                function(e) {
                    onMouseIn(this, timeout);
                }
                ,
                function (e) {
                    onMouseOut(this);
                }
            );
        } else if (hover_type == 'click') {

            $('.mega-nav').find('.dropdown-submenu').hover(
                function(e) {
                    onMouseIn(this, 100);
                }
                ,
                function (e) {
                    onMouseOut(this);
                }

            );

        }
        // for first li tag
        function redirect() {
            $('.dropdown-toggle').on('click',function(e){
                if($(this).parent().hasClass('open') && this.href && this.href != '#'){
                    window.location.href = this.href;
                    e.preventDefault();
                }
            });
        }
        function onMouseIn (e, timeout) {

            var $this = $(e);
            if ($this.hasClass('mega')) {
                $this.addClass ('hovering');
                clearTimeout ($this.data('hoverTime'));
                $this.data('hoverTime',
                    setTimeout(function(){$this.removeClass ('hovering')}, timeout));

                clearTimeout ($this.data('hoverTime'));
                $this.data('hoverTime',
                    setTimeout(function(){$this.addClass ('open')}, 100));
            } else {
                clearTimeout($this.data('hoverTime'));
                $this.data('hoverTime',
                    setTimeout(function () {
                        $this.addClass('open')
                    }, 100));
            }

        }

        function onMouseOut (e) {
            var $this = $(e);
            clearTimeout($this.data('hoverTime'));
            $this.data('hoverTime',
                setTimeout(function () {
                    $this.removeClass('open')
                }, 100));

        }

        /** BEGIN: off canvas menu **/
        var showOffCanvasMenu = function () {
            var $offcanvas = $('.offcanvas');
            var $body = $('body');
            var $wrapper = $('.wrapper');

            $body.addClass('overflow-hidden');
            $wrapper.addClass('offcanvas-push');

            var $overlay = $('<div />').addClass('offcanvas-overlay').appendTo('body');
            $overlay.css({
                top:0,
                right:0,
                bottom:0
            }).fadeIn();

            $overlay.click(function() {
                $body.removeClass('overflow-hidden');
                $wrapper.removeClass('offcanvas-push');
                $offcanvas.removeClass('active');
                $('.offcanvas-overlay').remove();
            });
        };
        var hideOffCanvasMenu = function () {
            var $body = $('body');
            var $wrapper = $('.wrapper');
            var $offcanvas = $('.offcanvas');

            $body.removeClass('overflow-hidden');
            $wrapper.removeClass('offcanvas-push');
            $offcanvas.removeClass('active');
            $('.offcanvas-overlay').remove();
        };
        $('[data-toggle=offcanvas]').click(function() {
            var $offcanvas = $('.offcanvas');
            $offcanvas.toggleClass('active');

            if ($offcanvas.hasClass('active')) {
                showOffCanvasMenu();
            }
            else {
                hideOffCanvasMenu();
            }
        });

        $('body').on('click', '.sidebar-nav a', function() {
            if (!$(this).hasClass('nav-oc-toggle')) hideOffCanvasMenu();
        });

        $('body').on('click', '.sidebar-close', function() {
            hideOffCanvasMenu();
        });

        // new off canvas submenu
        $('body').on('click', '.nav-oc-toggle', function() {
            var $this = $(this);
            var $parent = $this.closest('.nav-parent');

            if ($parent.find('> .submenu').hasClass('in')) $this.removeClass('icon-caret-up').addClass('icon-caret-down');
            else $this.removeClass('icon-caret-down').addClass('icon-caret-up');
        });
        /** END: off canvas menu **/
    });
}(jQuery);

我在服务器上的所有文件中搜索了303,这些文件带有重定向语句。

cms.php

public function redirect($url, $moved = false)

{
    // Handle B/C by checking if a message was passed to the method, will be removed at 4.0
if (func_num_args() > 1)
{
    $args = func_get_args();

    /*
     * Do some checks on the $args array, values below correspond to legacy redirect() method
     *
     * $args[0] = $url
     * $args[1] = Message to enqueue
     * $args[2] = Message type
     * $args[3] = $moved
     */
    if (isset($args[1]) && !empty($args[1]) && !is_bool($args[1]))
    {
        // Log that passing the message to the function is deprecated
        JLog::add(
            'Passing a message and message type to JFactory::getApplication()->redirect() is deprecated. '
            . 'Please set your message via JFactory::getApplication()->enqueueMessage() prior to calling redirect().',
            JLog::WARNING,
            'deprecated'
        );

        $message = $args[1];

        // Set the message type if present
        if (isset($args[2]) && !empty($args[2]))
        {
            $type = $args[2];
        }
        else
        {
            $type = null;
        }

        // Enqueue the message
        $this->enqueueMessage($message, $type);

        // Reset the $moved variable
        $moved = isset($args[3]) ? (boolean) $args[3] : false;
    }
}

application.php

public function redirect($url, $msg = '', $msgType = 'message', $moved = false)
    {
        // Check for relative internal links.
        if (preg_match('#^index2?\.php#', $url))
        {
            $url = JUri::base() . $url;
        }

        // Strip out any line breaks.
        $url = preg_split("/[\r\n]/", $url);
        $url = $url[0];

        /*
         * If we don't start with a http we need to fix this before we proceed.
         * We could validly start with something else (e.g. ftp), though this would
         * be unlikely and isn't supported by this API.
         */
        if (!preg_match('#^http#i', $url))
        {
            $uri = JUri::getInstance();
            $prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));

            if ($url[0] == '/')
            {
                // We just need the prefix since we have a path relative to the root.
                $url = $prefix . $url;
            }
            else
            {
                // It's relative to where we are now, so lets add that.
                $parts = explode('/', $uri->toString(array('path')));
                array_pop($parts);
                $path = implode('/', $parts) . '/';
                $url = $prefix . $path . $url;
            }
        }

        // If the message exists, enqueue it.
        if (trim($msg))
        {
            $this->enqueueMessage($msg, $msgType);
        }

        // Persist messages if they exist.
        if (count($this->_messageQueue))
        {
            $session = JFactory::getSession();
            $session->set('application.queue', $this->_messageQueue);
        }

        // If the headers have been sent, then we cannot send an additional location header
        // so we will output a javascript redirect statement.
        if (headers_sent())
        {
            echo "<script>document.location.href='" . str_replace("'", "&apos;", $url) . "';</script>\n";
        }
        else
        {
            $document = JFactory::getDocument();

            jimport('phputf8.utils.ascii');

            if (($this->client->engine == JApplicationWebClient::TRIDENT) && !utf8_is_ascii($url))
            {
                // MSIE type browser and/or server cause issues when url contains utf8 character,so use a javascript redirect method
                echo '<html><head><meta http-equiv="content-type" content="text/html; charset=' . $document->getCharset() . '" />'
                    . '<script>document.location.href=\'' . str_replace("'", "&apos;", $url) . '\';</script></head></html>';
            }
            else
            {
                // All other browsers, use the more efficient HTTP header method
                header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
                header('Location: ' . $url);
                header('Content-Type: text/html; charset=' . $document->getCharset());
            }
        }

        $this->close();
    }

web.php

public function redirect($url, $moved = false)
{
    // Import library dependencies.
    jimport('phputf8.utils.ascii');

    // Check for relative internal links.
    if (preg_match('#^index\.php#', $url))
    {
        // We changed this from "$this->get('uri.base.full') . $url" due to the inability to run the system tests with the original code
        $url = JUri::base() . $url;
    }

    // Perform a basic sanity check to make sure we don't have any CRLF garbage.
    $url = preg_split("/[\r\n]/", $url);
    $url = $url[0];

    /*
     * Here we need to check and see if the URL is relative or absolute.  Essentially, do we need to
     * prepend the URL with our base URL for a proper redirect.  The rudimentary way we are looking
     * at this is to simply check whether or not the URL string has a valid scheme or not.
     */
    if (!preg_match('#^[a-z]+\://#i', $url))
    {
        // Get a JUri instance for the requested URI.
        $uri = JUri::getInstance($this->get('uri.request'));

        // Get a base URL to prepend from the requested URI.
        $prefix = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));

        // We just need the prefix since we have a path relative to the root.
        if ($url[0] == '/')
        {
            $url = $prefix . $url;
        }
        // It's relative to where we are now, so lets add that.
        else
        {
            $parts = explode('/', $uri->toString(array('path')));
            array_pop($parts);
            $path = implode('/', $parts) . '/';
            $url = $prefix . $path . $url;
        }
    }

    // If the headers have already been sent we need to send the redirect statement via JavaScript.
    if ($this->checkHeadersSent())
    {
        echo "<script>document.location.href='" . str_replace("'", "&apos;", $url) . "';</script>\n";
    }
    else
    {
        // We have to use a JavaScript redirect here because MSIE doesn't play nice with utf-8 URLs.
        if (($this->client->engine == JApplicationWebClient::TRIDENT) && !utf8_is_ascii($url))
        {
            $html = '<html><head>';
            $html .= '<meta http-equiv="content-type" content="text/html; charset=' . $this->charSet . '" />';
            $html .= '<script>document.location.href=\'' . str_replace("'", "&apos;", $url) . '\';</script>';
            $html .= '</head><body></body></html>';

            echo $html;
        }
        else
        {
            // All other cases use the more efficient HTTP header for redirection.
            $this->header($moved ? 'HTTP/1.1 301 Moved Permanently' : 'HTTP/1.1 303 See other');
            $this->header('Location: ' . $url);
            $this->header('Content-Type: text/html; charset=' . $this->charSet);
        }
    }

0 个答案:

没有答案