سؤال
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!
المحلول
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 reviewsreview/customer/view/id/{review id}
- customer account view of a single reviewreview/product/list/id/{product id}/[(category)/{category id}]
- list of reviews for a productreview/product/post
- process action for posting a reviewreview/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);
}
}
نصائح أخرى
In order to avoid problems of duplicate content, you can customize the NOINDEX
robots directive for all the pages of this type : http://www.yourdomain.com/review/product/list/id/1 aby editing the file review.xml (tested magento 1.9 at least)
Here is the way to do it:
Copy the file /app/design/frontend/base/default/layout/review.xml to /app/design/frontend/yourthemepath/layout/review.xml if it doesn't exist in your theme already.
In this file, look for the handler
<review_product_list>
Under this handler, look for
<reference name="head">
Then simply add the line of code below between
<reference name="head">
and</reference>
. It will override general robots settings toNOINDEX, FOLLOW
Code to be added in the section:
<action method="setRobots"><value>NOINDEX,FOLLOW</value></action>
Refresh Magento cache, and look for updated
NOINDEX,FOLLOW
value in the source code of the page /review/product/list/id/1. It should give you something like this under<head>
:<meta name="robots" content="INDEX,FOLLOW" />
Google and other indexing robots will take this into account in their crawls.