Perforce Chronicle 2012.2/486814
API Documentation

Url_Redirector Class Reference

A controller plugin to handle redirecting outdated custom-urls to more permanent locations. More...

List of all members.

Public Member Functions

 routeShutdown (Zend_Controller_Request_Abstract $request)
 After the request is routed, check if we routed against an old (deleted) url path and if so, redirect (301) to a more permanent url.

Detailed Description

A controller plugin to handle redirecting outdated custom-urls to more permanent locations.

This allows us to honor old (deleted) url paths and redirect the user to a more appropriate path.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Url_Redirector::routeShutdown ( Zend_Controller_Request_Abstract $  request)

After the request is routed, check if we routed against an old (deleted) url path and if so, redirect (301) to a more permanent url.

Parameters:
Zend_Controller_Request_Abstract$requestthe request being routed.
Returns:
void
    {
        // nothing to do if our route is not in effect.
        $front  = Zend_Controller_Front::getInstance();
        $router = $front->getRouter();
        if (!$router->hasRoute(Url_Module::ROUTE)) {
            return;
        }
     
        // if routed url is deleted, redirect to a more permanent location.
        $route  = $router->getRoute(Url_Module::ROUTE);
        $url    = $route->getCurrentUrl();
        if ($url && $url->isDeleted() && $url->getPath() === trim($request->getPathInfo(), '/')) {
            $redirectUrl = null;
            $redirector  = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');

            // look for a better (non-deleted) custom url for these params.
            try {
                $redirectUrl = Url_Model_Url::fetchByParams($url->getParams())->getPath();
                $redirector->gotoUrlAndExit(
                    $request->getBaseUrl() . '/' . $redirectUrl,
                    array('code' => 301)
                );
            } catch (P4Cms_Record_NotFoundException $e) {
                // no better url for these params.
            }
        }
    }

The documentation for this class was generated from the following file: