News:

Support the VirtueMart project and become a member

Main Menu

Applying 301 redirects to child-products

Started by OriyanJ, October 23, 2016, 08:36:08 AM

Previous topic - Next topic

OriyanJ

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?
VirtueMart 3.2.2

Jumbo!

#1
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_idfalse);

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;
}
}

OriyanJ

VirtueMart 3.2.2