Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions administrator/language/en-GB/plg_system_sef.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

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_LABEL="Site Domain"
; Deprecated, will be removed in 7.0
PLG_SEF_ENFORCESUFFIX_DESCRIPTION="When enabled and \"Add Suffix to URL\" is also enabled, URLs without suffix will be redirected to the correct one. From version 6.0 onwards this will be the standard behavior and not an option anymore."
; Deprecated, will be removed in 7.0
PLG_SEF_ENFORCESUFFIX_LABEL="Enforce a suffix by redirect"
PLG_SEF_INDEXPHP_DESCRIPTION="This option enables a stricter handling of 'index.php' in URLs when 'Use URL Rewriting' is enabled in Global Configuration. It will remove 'index.php' if a URL still contains it and redirect incoming requests with 'index.php' to the version without the 'index.php'."
PLG_SEF_INDEXPHP_LABEL="Strict handling of index.php"
Expand Down
2 changes: 1 addition & 1 deletion installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
(0, 'plg_system_remember', 'plugin', 'remember', 'system', 0, 1, 1, 0, 1, '', '', '', 16, 0),
(0, 'plg_system_schedulerunner', 'plugin', 'schedulerunner', 'system', 0, 1, 1, 0, 1, '', '{}', '', 17, 0),
(0, 'plg_system_schemaorg', 'plugin', 'schemaorg', 'system', 0, 1, 1, 0, 1, '', '{}', '', 18, 0),
(0, 'plg_system_sef', 'plugin', 'sef', 'system', 0, 1, 1, 0, 1, '', '{"domain":"","indexphp":"1","trailingslash":"0","enforcesuffix":"1","strictrouting":"1"}', '', 19, 0),
(0, 'plg_system_sef', 'plugin', 'sef', 'system', 0, 1, 1, 0, 1, '', '{"domain":"","indexphp":"1","trailingslash":"0","strictrouting":"1"}', '', 19, 0),
(0, 'plg_system_shortcut', 'plugin', 'shortcut', 'system', 0, 1, 1, 0, 1, '', '{}', '', 21, 0),
(0, 'plg_system_skipto', 'plugin', 'skipto', 'system', 0, 1, 1, 0, 1, '', '{}', '', 22, 0),
(0, 'plg_system_stats', 'plugin', 'stats', 'system', 0, 1, 1, 0, 1, '', '', '', 23, 0),
Expand Down
2 changes: 1 addition & 1 deletion installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
(0, 'plg_system_remember', 'plugin', 'remember', 'system', 0, 1, 1, 0, 1, '', '', '', 16, 0),
(0, 'plg_system_schedulerunner', 'plugin', 'schedulerunner', 'system', 0, 1, 1, 0, 1, '', '{}', '', 17, 0),
(0, 'plg_system_schemaorg', 'plugin', 'schemaorg', 'system', 0, 1, 1, 0, 1, '', '{}', '', 18, 0),
(0, 'plg_system_sef', 'plugin', 'sef', 'system', 0, 1, 1, 0, 1, '', '{"domain":"","indexphp":"1","trailingslash":"0","enforcesuffix":"1","strictrouting":"1"}', '', 19, 0),
(0, 'plg_system_sef', 'plugin', 'sef', 'system', 0, 1, 1, 0, 1, '', '{"domain":"","indexphp":"1","trailingslash":"0","strictrouting":"1"}', '', 19, 0),
(0, 'plg_system_shortcut', 'plugin', 'shortcut', 'system', 0, 1, 1, 0, 1, '', '{}', '', 21, 0),
(0, 'plg_system_skipto', 'plugin', 'skipto', 'system', 0, 1, 1, 0, 1, '', '{}', '', 22, 0),
(0, 'plg_system_stats', 'plugin', 'stats', 'system', 0, 1, 1, 0, 1, '', '', '', 23, 0),
Expand Down
23 changes: 21 additions & 2 deletions libraries/src/Router/SiteRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,31 @@ public function parseFormat(&$router, &$uri)
{
$route = $uri->getPath();

// Identify format
if (!(str_ends_with($route, 'index.php') || str_ends_with($route, '/')) && $suffix = pathinfo($route, PATHINFO_EXTENSION)) {
if (!(str_ends_with($route, 'index.php') || str_ends_with($route, '/'))) {
// We don't want suffixes when the URL ends in index.php or with a /
return;
}

$suffix = pathinfo($route, PATHINFO_EXTENSION);
$nonSEFSuffix = $uri->getVar('format');

if ($suffix) {
$uri->setVar('format', $suffix);
$route = str_replace('.' . $suffix, '', $route);
$uri->setPath($route);
}

if ($nonSEFSuffix) {
// There is a URL query parameter named "format"
$uri->setVar('format', $nonSEFSuffix);
$router->setTainted();
}

if (!$suffix) {
// We don't have a suffix, so we default to .html at the end
$uri->setPath($route . '.html');
$router->setTainted();
}
}

/**
Expand Down
13 changes: 0 additions & 13 deletions plugins/system/sef/sef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,6 @@
validate="url"
/>

<field
name="enforcesuffix"
type="list"
label="PLG_SEF_ENFORCESUFFIX_LABEL"
description="PLG_SEF_ENFORCESUFFIX_DESCRIPTION"
layout="joomla.form.field.radio.switcher"
default="0"
filter="boolean"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
name="indexphp"
type="radio"
Expand Down
57 changes: 0 additions & 57 deletions plugins/system/sef/src/Extension/Sef.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Joomla\CMS\Event\Application\AfterInitialiseEvent;
use Joomla\CMS\Event\Application\AfterRenderEvent;
use Joomla\CMS\Event\Application\AfterRouteEvent;
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Router\Router;
Expand Down Expand Up @@ -143,11 +142,6 @@ public function onAfterRoute(AfterRouteEvent $event)
$this->enforceTrailingSlash();
}

// Enforce adding a suffix with a redirect
if ($app->get('sef') && $app->get('sef_suffix') && $this->params->get('enforcesuffix')) {
$this->enforceSuffix();
}

// Enforce SEF URLs
if ($this->params->get('strictrouting') && $app->getInput()->getMethod() == 'GET') {
$this->enforceSEF();
Expand Down Expand Up @@ -323,57 +317,6 @@ function ($match) use ($base, $protocols) {
$app->setBody($buffer);
}

/**
* Enforce the URL suffix with a redirect
*
* @return void
*
* @since 5.2.0
*/
public function enforceSuffix()
{
$origUri = Uri::getInstance();
$route = $origUri->getPath();

if (str_ends_with($route, 'index.php') || str_ends_with($route, '/')) {
// We don't want suffixes when the URL ends in index.php or with a /
return;
}

// We don't force a suffix for the language homepage
$segments = explode('/', $route);
$last = array_pop($segments);
$sefs = LanguageHelper::getLanguages('sef');

if ($this->getApplication()->getLanguageFilter() && isset($sefs[$last])) {
return;
}

$suffix = pathinfo($route, PATHINFO_EXTENSION);
$nonSEFSuffix = $origUri->getVar('format');

if ($nonSEFSuffix && $suffix !== $nonSEFSuffix) {
// There is a URL query parameter named "format", which isn't the same to the suffix
$pathWithoutSuffix = ($suffix !== '') ? substr($route, 0, -(\strlen($suffix) + 1)) : $route;

$origUri->delVar('format');
$origUri->setPath($pathWithoutSuffix . '.' . $nonSEFSuffix);
$this->getApplication()->redirect($origUri->toString(), 301);
}

if ($suffix && $suffix == $nonSEFSuffix) {
// There is a URL query parameter named "format", which is identical to the suffix
$origUri->delVar('format');
$this->getApplication()->redirect($origUri->toString(), 301);
}

if (!$suffix) {
// We don't have a suffix, so we default to .html at the end
$origUri->setPath($route . '.html');
$this->getApplication()->redirect($origUri->toString(), 301);
}
}

/**
* Enforce removal of index.php with a redirect
*
Expand Down
Loading