Magento – Disable reviews page

review

I have successfully added "reviews list" and "add review form" to the product page.

Now I just want to completely disable reviews page (http://example.com/review/...)? (so search engines won't accidentally find and crawl it, noindex and canonical aren't an option).

Thank you for help!

Best Answer

There are several routes in the Mage_Reviews module, and you likely don't want to disable them all. Here's a list gleaned from Mage/Reviews/controllers/:

  • review/customer/(index) - customer account view of their reviews
  • review/customer/view/id/{review id} - customer account view of a single review
  • review/product/list/id/{product id}/[(category)/{category id}] - list of reviews for a product
  • review/product/post - process action for posting a review
  • review/product/view/id/{review id} - individual view for a single product review - keep?

Bold = paths which you do/might want to map & redirect, italics = paths to keep.

Whereas there is content which can and should be used for the review requests, this seems best accomplished using an observer. To catch the review/product/list route the observer should observe the controller_action_predispatch_review_product_list event in the frontend event area and set an HTTP 301 redirect to the product page. The 301 will of course be used by search engines to update links and transfer some of the link juice.

<frontend>
    <events>
        <controller_action_predispatch_review_product_list>
            <observers>
                <your_module>
                    <class>your_module/observer</class>
                    <method>redirectReviewListToProductView</method>
                </your_module>
            </observers>
        </controller_action_predispatch_review_product_list>
    </events>
</frontend>

And in your module's observer, the redirect method:

/**
 * Redirect requests for review page to product page,
 * which now contains review contents. Relies on the
 * accommodation of request object redirect in the
 * elseif condition which is present in
 * Mage_Review_ProductController::listAction().
 *
 * Observes
 * controller_action_predispatch_review_product_list
 *
 * @see Mage_Review_ProductController::listAction()
 * @see Mage_Core_Controller_Varien_Action::preDispatch()
 *
 * @param Varien_Event_Observer $observer
 */
public function redirectReviewListToProductView(Varien_Event_Observer $observer)
{
    $request = $observer->getControllerAction()->getRequest();
    /* @var $request Mage_Core_Controller_Request_Http */

    //log to custom logfile
    //Mage::log($request->getServer('HTTP_REFERER').': '.$request->getPathInfo(), Zend_Log::INFO, 'review_redirects.log',true);

    //$toUrl will be empty if missing id param or invalid product ID.
    $toUrl = Mage::getModel('catalog/product')->load($request->getParam('id'))->getProductUrl();

    //$request->_forward() is protected (no idea why), so implement noroute (404) manually.
    if (!$toUrl) {
        $request->initForward();
        $request->setActionName('noroute')->setDispatched(false);
    }
    else {
        //review/product/list accommodates redirects, so this should work
        $observer->getControllerAction()->getResponse()->setRedirect($toUrl);
        $request->setParam('id',false);
    }
}
Related Topic