Skip to content

Commit

Permalink
apply sef autocorrection
Browse files Browse the repository at this point in the history
  • Loading branch information
alex7r committed Jun 19, 2017
1 parent 5b6abe8 commit 81b2a05
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion administrator/language/en-GB/en-GB.plg_system_sef.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
PLG_SEF_XML_DESCRIPTION="Adds SEF support to links in the document. It operates directly on the HTML and does not require a special tag."
PLG_SYSTEM_SEF="System - SEF"
PLG_SEF_DOMAIN_LABEL="Site Domain"
PLG_SEF_DOMAIN_DESCRIPTION="If your site can be accessed through more than one domain enter the preferred (sometimes referred to as canonical) domain here. <br /><strong>Note:</strong> https://example.com and https://www.example.com are different domains."
PLG_SEF_DOMAIN_DESCRIPTION="If your site can be accessed through more than one domain enter the preferred (sometimes referred to as canonical) domain here. <br /><strong>Note:</strong> https://example.com and https://www.example.com are different domains."
PLG_SEF_AUTOREDIRECT_LABEL="Auto redirect"
PLG_SEF_AUTOREDIRECT_DESCRIPTION="Enable this option if you want to use urls autocorrection (if possible)."
27 changes: 27 additions & 0 deletions plugins/system/sef/sef.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,33 @@ public function onAfterDispatch()
$doc->addHeadLink(htmlspecialchars($canonical), 'canonical');
}

/**
* AutoCorrect SEF url so there is no content-duplicates
*
* @return void
* @since __DEPLOY_VERSION__
*/
public function onAfterRoute()
{
if ($this->params->get('autoredirect', true))
{
if (!JFactory::getApplication()->isClient('administrator') && !JFactory::getApplication()->input->post->getArray())
{
$uri = JUri::getInstance();
$vars = JFactory::getApplication()->input->getArray();
$query = array();
foreach ($vars as $k => $v)
{
$query[] = $k . '=' . $v;
}
if ($uri->getPath() . ($uri->getQuery() ? '?' . $uri->getQuery() : '') != JRoute::_('index.php?' . implode('&', $query)))
{
JFactory::getApplication()->redirect(JRoute::_('index.php?' . implode('&', $query)), 301);
}
}
}
}

/**
* Convert the site URL to fit to the HTTP request.
*
Expand Down
11 changes: 11 additions & 0 deletions plugins/system/sef/sef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
filter="url"
validate="url"
/>
<field
name="autoredirect"
type="radio"
label="PLG_SEF_AUTOREDIRECT_LABEL"
description="PLG_SEF_AUTOREDIRECT_DESCRIPTION"
class="btn-group btn-group-yesno"
default="1"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
</fieldset>
</fields>
</config>
Expand Down

0 comments on commit 81b2a05

Please sign in to comment.