?
avatar DeWillem78
DeWillem78
30 Nov 2018

Steps to reproduce the issue

Install Joomla on a server running nginx as a proxy to Apache.
Enable multi language.
Open homepage.

Expected result

The language filter plugin should redirect https://my.site/ to https://my.site/en

Actual result

A redirect is done to https://my.site/en/ with a trailing slash. Since "en" is not an existing directory in the web root, nginx returns a 404 not found HTTP status. When path is empty (while building the new url in the language filter plugin I assume), there should not be a trailing slash.

System information (as much as possible)

Plesk Onyx Version 17.8.11 Update 31
CentOS Linux 7.5.1804
PHP 7.2.12
Percona 5.7.23-25
Joomla! 3.9.1

Additional comments

I've searched the net for a while. There are more people running into issues caused by the trailing slash. Most of them edit the .htaccess file to remove the trailing slash, causing difficulties with /administrator and some other links. Always having two redirects is far from ideal. It's also a workaround instead of a solution to the actual problem.

The same trailing slash is added in a blog type link. https://my.site/en/blog/ should be https://my.site/en/blog

Cheers, Willem

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
3.00

avatar DeWillem78 DeWillem78 - open - 30 Nov 2018
avatar joomla-cms-bot joomla-cms-bot - labeled - 30 Nov 2018
avatar infograf768
infograf768 - comment - 1 Dec 2018

I have posted a possible solution on the forum.
I am not sure it would be B/C. @mbabker ?
Here is the .diff to test

diff --git a/modules/mod_languages/tmpl/default.php b/modules/mod_languages/tmpl/default.php
index 0192c3f..eb9c061 100644
--- a/modules/mod_languages/tmpl/default.php
+++ b/modules/mod_languages/tmpl/default.php
@@ -27,4 +27,5 @@
 	<select class="inputbox advancedSelect" onchange="document.location.replace(this.value);" >
 	<?php foreach ($list as $language) : ?>
+	<?php $language->link = rtrim($language->link, '/'); ?>
 		<option dir=<?php echo $language->rtl ? '"rtl"' : '"ltr"'; ?> value="<?php echo htmlspecialchars_decode(htmlspecialchars($language->link, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES); ?>" <?php echo $language->active ? 'selected="selected"' : ''; ?>>
 		<?php echo $language->title_native; ?></option>
@@ -35,4 +36,5 @@
 	<div class="btn-group">
 		<?php foreach ($list as $language) : ?>
+		<?php $language->link = rtrim($language->link, '/'); ?>
 			<?php if ($language->active) : ?>
 				<a href="#" data-toggle="dropdown" class="btn dropdown-toggle">
@@ -47,4 +49,5 @@
 		<ul class="<?php echo $params->get('lineheight', 0) ? 'lang-block' : 'lang-inline'; ?> dropdown-menu" dir="<?php echo JFactory::getLanguage()->isRtl() ? 'rtl' : 'ltr'; ?>">
 		<?php foreach ($list as $language) : ?>
+		<?php $language->link = rtrim($language->link, '/'); ?>
 			<?php if (!$language->active) : ?>
 				<li>
@@ -73,4 +76,5 @@
 	<ul class="<?php echo $params->get('inline', 1) ? 'lang-inline' : 'lang-block'; ?>" dir="<?php echo JFactory::getLanguage()->isRtl() ? 'rtl' : 'ltr'; ?>">
 	<?php foreach ($list as $language) : ?>
+		<?php $language->link = rtrim($language->link, '/'); ?>
 		<?php if (!$language->active) : ?>
 			<li>
diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php
index 7ab830b..8d17606 100644
--- a/plugins/system/languagefilter/languagefilter.php
+++ b/plugins/system/languagefilter/languagefilter.php
@@ -228,5 +228,5 @@
 			|| $lang !== $this->current_lang))
 		{
-			$uri->setPath($uri->getPath() . '/' . $sef . '/');
+			$uri->setPath($uri->getPath() . '/' . $sef);
 		}
 	}
@@ -836,4 +836,5 @@
 				foreach ($languages as $i => &$language)
 				{
+					$language->link = rtrim($language->link, '/');
 					$doc->addHeadLink($server . $language->link, 'alternate', 'rel', array('hreflang' => $i));
 				}
avatar infograf768
infograf768 - comment - 1 Dec 2018

btw, I do not have here a trailing slash for any menu items except home before this proposed patch.
But it could solve your issue if you get one.
The .diff proposed deals with menu items, language switcher and hreflang and is in my tests case specifically useful for Homes.

avatar DeWillem78
DeWillem78 - comment - 2 Dec 2018

Hi, thanks for the quick reply!
For me also, all the normal links to articles don't have a trailing slash.
If I understand correctly, you strip the trailing slash off of any link. On one hand that seems very reliable because it would work on all links processed by this code. On the other hand, wouldn't it be better to not add the slash there in the first place? So far I've only seen it happen in the language plugin and blog type link. For consistency and efficiency I'd probably change those instead of repairing it afterwards.
Don't get me wrong though, I really appreciate your effort!

Willem

avatar infograf768
infograf768 - comment - 2 Dec 2018

The way I see it, the trailing slash is specific to multilingual sites and even more specific to the Home pages of such sites where only the sef url language code is displayed after the domain or after TLD/index.php

Therefore this PR deals only with the multilingual module switcher and language filter plugin.

As I said, I can't reproduce the trailing slash for any other loaded page, including /blog but I guess the pr would solve your issue too. Please test.

avatar franz-wohlkoenig franz-wohlkoenig - change - 4 Mar 2019
Status New Information Required
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 4 Mar 2019

any Comment @DeWillem78 or can this Issue be closed?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/23209.

avatar franz-wohlkoenig
franz-wohlkoenig - comment - 4 Mar 2019

any Comment @DeWillem78 or can this Issue be closed?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/23209.

avatar joomla-cms-bot joomla-cms-bot - change - 16 Mar 2019
Closed_By franz-wohlkoenig joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 16 Mar 2019
avatar franz-wohlkoenig franz-wohlkoenig - change - 16 Mar 2019
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2019-03-16 07:04:39
Closed_By franz-wohlkoenig
avatar joomla-cms-bot
joomla-cms-bot - comment - 16 Mar 2019
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 16 Mar 2019

Closed as no Answer, please reopen if needed.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/23209.

Add a Comment

Login with GitHub to post a comment