Duplicate Pages in Joomla - solution

Discussion in 'Joomla' started by Amigo9876, Aug 6, 2013.

  1. #1
    The same page can be accessed by multiple url's:
    For example:
    site.com/index.php?option=com_content&view=article&id=22
    site.com/news/tech/1.html
    site.com/news/tech/1-news.html
    site.com/news/tech/1-newsnewsnewnsnsns.html
    site.com/1-news/2-tech/1dsfsdkgjdfgklhfdgjf
    site.com/home/1.html


    This is not good.
    The solution - automatic redirect to a normal url
    For frontpage:
    /templates/your-theme/html/com_content/frontpage/default.php
    Paste this code(first line file)
    <?php defined('_JEXEC') or die('Restricted access');
    $this->original_link = "/";
    if (JRequest::getInt('start') > 0) $this->original_link .= "index.php?start=" . JRequest::getVar('start');
    $this->real_link = JRequest::getURI();
    if ($this->original_link != $this->real_link) JApplication::redirect($this->original_link);
    ?>
    Code (markup):
    For Pages (Articles):
    /templates/your-theme/html/com_content/article/default.php
    <?php defined('_JEXEC') or die('Restricted access');
    if ($this->article->readmore_link != JRequest::getURI()) JApplication::redirect($this->article->readmore_link);
    ?>
    Code (markup):
    For Category:
    /templates/your-theme/html/com_content/category/blog.php
    <?php defined('_JEXEC') or die('Restricted access');
    $this->original_link = JRoute::_(ContentHelperRoute::getCategoryRoute(JRequest::getVar('id'), 0));
    if (JRequest::getInt('start') > 0) $this->original_link .= "?start=" . JRequest::getVar('start');
    $this->real_link = JRequest::getURI();
    if ($this->original_link != $this->real_link) JApplication::redirect($this->original_link);
    ?>
    Code (markup):
    For Section:
    /templates/your-theme/html/com_content/section/blog.php
    <?php defined('_JEXEC') or die('Restricted access');
    $this->original_link = JRoute::_(ContentHelperRoute::getSectionRoute(JRequest::getVar('id')));
    if (JRequest::getInt('start') > 0) $this->original_link .= "?start=" . JRequest::getVar('start');
    $this->real_link = JRequest::getURI();
    if ($this->original_link != $this->real_link) JApplication::redirect($this->original_link);
    ?>
    Code (markup):
    Try it. Enjoy.
    Author:
     
    Amigo9876, Aug 6, 2013 IP
  2. sarah_23

    sarah_23 Active Member

    Messages:
    150
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    78
    Digital Goods:
    1
    #2
    Highly useful, thank you. i was looking for this solutions since ages for my joomla forum website abeyaar.com
     
    sarah_23, Nov 15, 2013 IP