I'm selling organised tours, I'm making them disappear from category view when product_available_date had passed. But access to them is still available with Google or by using their direct links.
I want to create 301 redirection from a child to it's parent. I have no clue where to start with that. I can't do it at the product's detail page level. Anyone have an idea?
You can try adding the following codes at the top of product details page layout.
Original VirtueMart component layout file: components/com_virtuemart/views/productdetails/tmpl/default.php
OR
Template HTML override file: templates/YOUR-JOOMLA-TEMPLATE/html/com_virtuemart/productdetails/default.php
<?php
defined('_JEXEC') or die('Restricted access');
if(!empty($this->product) && !empty($this->product->product_parent_id))
{
$app = JFactory::getApplication();
$referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
$parent_url = JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->product_parent_id .
'&virtuemart_category_id=' . $this->product->virtuemart_category_id, false);
if(empty($referrer))
{
$app->redirect($parent_url);
return false;
}
$parts = parse_url($referrer);
$host = isset($parts['host']) ? $parts['host'] : null;
if(!empty($host) && strpos(JUri::root(), $host) === false)
{
$app->redirect($parent_url);
return false;
}
}
Great answer Jumbo. Thank you very much.