? Pending

User tests: Successful: Unsuccessful:

avatar csthomas
csthomas
11 Dec 2018

Pull Request for Issue #23209 and #23144

Summary of Changes

  1. Remove default sef from URL when "Remove URL Language Code" is set to ON in the language filter plugin.
  2. Remove trailing slash after sef.
  3. Replace /en/ to /en.html when "Add Suffix to URL" is ON, I'm not sure about B/C for that.
  4. Correct the active language link (mod_languages) when you are on /en/:
    • when "Add Suffix to URL" is ON then link is corrected to /en.html
    • when "Add Suffix to URL" is OFF then link is corrected to /en (remove trailing slash)

Testing Instructions

Multilingual webisite with associations.

Expected result

Issues fixed.

Actual result

Documentation Changes Required

??

avatar csthomas csthomas - open - 11 Dec 2018
avatar csthomas csthomas - change - 11 Dec 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 11 Dec 2018
Category Modules Front End Plugins
avatar infograf768
infograf768 - comment - 12 Dec 2018

Trailing slash is solved.

Remains some issues.

Settings

en-GB set as default site language. Show active language is ON.
Other languages are fr-FR and it-IT
"Add Suffix to URL" set to OFF

For example:
Associated categories for the 3 languages on my test site.
Creating for each language a category blog menu item for these associated categories.
Loading the menu item for French or Italian

Result
The link in the module to the en-GB one contains the sef suffix
http://localhost:8888/installmulti/trunkgitnew/en/catblogenglish
It should be
http://localhost:8888/installmulti/trunkgitnew/catblogenglish

It is the correct link in the alternate

<link href="http://localhost:8888/installmulti/trunkgitnew/fr/catblogfrench" rel="alternate" hreflang="fr-FR" />
	<link href="http://localhost:8888/installmulti/trunkgitnew/catblogenglish" rel="alternate" hreflang="en-GB" />
	<link href="http://localhost:8888/installmulti/trunkgitnew/it/catblogitalian" rel="alternate" hreflang="it-IT" />

Settings

same but "Add Suffix to URL" set to ON

Loading the Home page for Italian or French

Result
The link in the module to the en-GB home contains the sef suffix and html (/en.html)
It should be
http://localhost:8888/installmulti/trunkgitnew/

Same for the alternate.

<link href="http://localhost:8888/installmulti/trunkgitnew/fr.html" rel="alternate" hreflang="fr-FR" />
	<link href="http://localhost:8888/installmulti/trunkgitnew/en.html" rel="alternate" hreflang="en-GB" />
	<link href="http://localhost:8888/installmulti/trunkgitnew/it.html" rel="alternate" hreflang="it-IT" />

Question btw:
Never heard about routing an ampersand. What is it supposed to do? Any doc on this?
$language->link = JRoute::_('&');

avatar csthomas csthomas - change - 12 Dec 2018
Labels Added: ?
avatar csthomas
csthomas - comment - 12 Dec 2018

Fixed

avatar csthomas
csthomas - comment - 12 Dec 2018

Question btw:
Never heard about routing an ampersand. What is it supposed to do? Any doc on this?
$language->link = JRoute::_('&');

This is almost the same

$language->link = JRoute::_('&Itemid=' . $homes['*']->id);

but at this line you override Itemid.

avatar infograf768
infograf768 - comment - 13 Dec 2018

Issue solved when "Add Suffix to URL" set to OFF. πŸ‘

Issue not solved when "Add Suffix to URL" set to ON.
we still get /en.html instead of / both for the module and alternate.

avatar Bakual
Bakual - comment - 13 Dec 2018

I also don't understand what JRoute::_('&') is supposed to do.
The other line you referenced does a valid URL (eg "index.php?Itemid=123"), while yours would do just something like "index.php?"?

avatar csthomas
csthomas - comment - 13 Dec 2018

@infograf768
I'm not sure if I understand your case.

My case:

If English is your default language and you are on /fr/... or /it/... and you want to go to the English home page, you have to go to /en.html or /en first, to change the cookie, after that you will be redirected to /. You can enter directly in the browser URL / and check what will happen.

If you are on /fr/blog-fr.html and want to go to the English blog /blog-en.html then Joomla does not have to go /en/blog-en.html. BUT if you want to go to the English homepage then / won't work and you have to go first to /en.html which will redirect you to /.

This auto change function (hard coded) based on the cookie language when you go directly to the domain home page /.

Take a look at the code:

$sef = $parts[0];
// Do we have a URL Language Code ?
if (!isset($this->sefs[$sef]))
{
// Check if remove default URL language code is set
if ($this->params->get('remove_default_prefix', 0))
{
if ($parts[0])
{
// We load a default site language page
$lang_code = $this->default_lang;
}
else
{
// We check for an existing language cookie
$lang_code = $this->getLanguageCookie();
}
}
else
{
$lang_code = $this->getLanguageCookie();
}

avatar csthomas
csthomas - comment - 13 Dec 2018

Why I use JRoute::_('&').

Similar examples:

modules/mod_languages/helper.php:144:                                   $language->link = JRoute::_('&Itemid=' . $homes['*']->id);
libraries/src/Document/Renderer/Feed/AtomRenderer.php:62:               $syndicationURL = \JRoute::_('&format=feed&type=atom');
libraries/src/Document/Renderer/Feed/RssRenderer.php:58:                $syndicationURL = \JRoute::_('&format=feed&type=rss');

For example, I have a canonical page to my article /blog/14-subcategory/123-article.
Then I move my article to another category 15-opinions and the new canonical URL will be /blog/15-opinions/123-article.

And now some visitor goes to the old link /blog/14-subcategory/123-article, which still work.
Then Joomla for:

  • JUri::getInstance()->toString(array('path', 'query')); - (before this PR) will return /blog/14-subcategory/123-article
  • JRoute::_('&')); will return /blog/15-opinions/123-article.

To make sure I use it correctly and I do not break B/C, @Hackwar, can you add your review.

avatar Bakual
Bakual - comment - 13 Dec 2018

Your other cases add something to the URL, so it makes partly sense. Imho better would be there to enter the full non-SEF URL so JRoute has all correct information and doesn't base on current URL.
In your case, you don't add anything, so that ampersand is superfluous and confusing.
For referencing the current URL we have used JRoute::_('') in one other place (registration form). I'm not even sure this works, personally I wouldn't do that either.

avatar csthomas
csthomas - comment - 13 Dec 2018

To test the following, it does not have to be a multilingual website.

Please go to the third (at least the second) page of your article, ex: /pl/blog-pl/2-artykul-pl-pl?start=2 and put this code in the active template index.php:

<?php $limitstart = \JFactory::getApplication()->input->get('limitstart'); ?>
<p>1. <?php echo JRoute::_('index.php'); ?></p>
<p>2. <?php echo JRoute::_('&format=feed&type=atom'); ?></p>
<p>3. <?php echo JRoute::_(''); ?></p>
<p>4. <?php echo JRoute::_('&'); ?></p>
<p>5. <?php echo JRoute::_('&' . ($limitstart !== null ? "limitstart=$limitstart" : '')); ?></p>

I got:

1. /pl/blog-pl
2. /pl/blog-pl/2-artykul-pl-pl?format=feed&type=atom
3.
4. /pl/blog-pl/2-artykul-pl-pl
5. /pl/blog-pl/2-artykul-pl-pl?start=2
  1. It is a link to the current menu item only, it removes article part
  2. It is almost the current URL but with additional parameters ?format=feed&type=atom
  3. It is only empty string, href=""
  4. It is the article URL but on the first page, this is a bug in J3, IIRC fixed in J4
  5. It the current URL where I am

After I turned off the SEF option I got:

1. /index.php?option=com_content&view=category&layout=blog&id=9&Itemid=105&lang=pl
2. /index.php?option=com_content&view=article&id=2:artykul-pl-pl&catid=9&lang=pl&limitstart=2&Itemid=105&format=feed&type=atom
3.
4. /index.php?option=com_content&view=article&id=2:artykul-pl-pl&catid=9&lang=pl&limitstart=2&Itemid=105
5. /index.php?option=com_content&view=article&id=2:artykul-pl-pl&catid=9&lang=pl&limitstart=2&Itemid=105
avatar infograf768
infograf768 - comment - 13 Dec 2018

@csthomas
the case concerns the home page.
the link/url to the default site language home page (html added or not in general ) in source when sef is set to not display, should always be the pure base, i.e. mydomain.com/ . It should NOT inlude the sef (en in this case) or en.html.
Evidently we still use the redirection internally (depending on cookie, browser settings, associations) but source output (module, alternate) should not include sef and html.

avatar csthomas
csthomas - comment - 13 Dec 2018

OK, this may be right, especially for the module cache, but if I did it, then it would not be a B/C break.
On J3.9.1 there is /en/ on this PR is /en but you want /.

avatar csthomas
csthomas - comment - 13 Dec 2018

Before this PR and on this PR if you go to domain.com/ then the language of the page depends on the cookie, or if not exists then the default language is used.

You want to skip cookie settings and always go to the default language home page.

avatar infograf768
infograf768 - comment - 13 Dec 2018

Not exactly and we should not skip cookie settings at all as it is used when you go back to the default site language home page.

In 3.9.1 (and before) we do get the alternate OK when "Add Suffix to URL" is set to NO

<link href="http://localhost:8888/installmulti/trunkgitnew/fr/" rel="alternate" hreflang="fr-FR" />
	<link href="http://localhost:8888/installmulti/trunkgitnew/" rel="alternate" hreflang="en-GB" />
	<link href="http://localhost:8888/installmulti/trunkgitnew/it/" rel="alternate" hreflang="it-IT" />

With the trailing slash for the non default site language, which is an issue for some system ad NGINX as the other issue righfully states.

But NOT for the module in source, which was the unique reason for the PR I had proposed #23178

With this patch, when we set "Add Suffix to URL" set to NO, all is correct (module and alternate)

Example for alternate:


	<link href="http://localhost:8888/installmulti/trunkgitnew/fr" rel="alternate" hreflang="fr-FR" />
	<link href="http://localhost:8888/installmulti/trunkgitnew/" rel="alternate" hreflang="en-GB" />
	<link href="http://localhost:8888/installmulti/trunkgitnew/it" rel="alternate" hreflang="it-IT" />

For the module, we get the same urls

It breaks when "Add Suffix to URL" set to YES although for en-GB it should be the same as above.

In 3.9.1, when "Add Suffix to URL" set to YES, we do not get any .html for the home pages. They remain as /sef/ (with the undesired trailing slash)
The suffix .html is only added for all other menu items/pages

Therefore I even wonder if we should add the suffix for the home pages, even if it is only for the non default site languages.

avatar infograf768
infograf768 - comment - 13 Dec 2018

NOTE: the cookie deals with the language code (en-GB), not the sef.

avatar csthomas
csthomas - comment - 13 Dec 2018

OK, there is two issues:

  • the first is the wrong link <link href="http://localhost:8888/installmulti/trunkgitnew/en" rel="alternate" hreflang="en-GB" /> I should remove /en
  • the second is the suffix .html in en.html, fr.html, etc. After I removed the last / then joomla starts adding .html automatically. I do not know how to fix it. Probably I can't.
avatar infograf768
infograf768 - comment - 13 Dec 2018

β€˜en’ is removed ok when Add Suffix to Url is set to No

avatar csthomas
csthomas - comment - 13 Dec 2018

/en is removed ok when Add Suffix to Url is set to No.

In my dev site is stay. Hmm?

avatar joomla-cms-bot joomla-cms-bot - change - 13 Dec 2018
Category Modules Front End Plugins Libraries Modules Front End Plugins
avatar csthomas
csthomas - comment - 13 Dec 2018

I have to ask, why we should not add the sufffix .html to home pages, such as /fr.html when "Add Suffix to URL" is set to YES? I know that previously it was /fr/.

Now to support NGINX we I had to remove the trailing slash.
Done.
Try this PR after the latest changes.

There is one magical change in SiteRouter. I'm not sure if this is the correct way to solve this problem.

avatar csthomas csthomas - change - 13 Dec 2018
The description was changed
avatar csthomas csthomas - edited - 13 Dec 2018
avatar infograf768
infograf768 - comment - 14 Dec 2018

I have to ask, why we should not add the sufffix .html to home pages, such as /fr.html when "Add Suffix to URL" is set to YES? I know that previously it was /fr/.

It would not be B/C.
Will test now the changes, but trailing slashes were already removed before.

avatar csthomas
csthomas - comment - 14 Dec 2018

This changes probably also break something, I'm working on two different versions.

avatar infograf768
infograf768 - comment - 14 Dec 2018

.html is now gone from home pages. Good.

But we are back to the issue I was solving in #23178
I.e. the url for the module to the default site language in SOURCE is displaying the sef (it does not and is OK in the alternate):

<a href="/installmulti/trunkgitnew/en"> etc.

I solved this issue here by setting a cookie in languagefilter lines 256 to 265

		if ($this->params->get('remove_default_prefix', 0)
			&& $lang === $this->default_lang)
			//&& $lang === $this->current_lang) // REMOVED
		{
			// Remove /sef/ from index.php/sef/
			$uri->setPath(substr_replace($path, '', 9, strlen($sef) + 1));

			$this->setLanguageCookie($lang); // ADDED
		}
		elseif ($path === "index.php/$sef/")

Note: I could not find anywhere where is defined the code skipFormat

avatar csthomas
csthomas - comment - 14 Dec 2018

Your fix and #23178 will break behaviour as follow.

Go to /fr page, then joomla will change your cookie to default language EN (because of some link to English version).
Then close your browser and open again at https://domain.com/.
Now you will see the change:

  • before your patch, you will be redirected to /fr
  • after your patch or #23178 you will stay at the English version /.
avatar infograf768
infograf768 - comment - 14 Dec 2018

you are right.

avatar infograf768
infograf768 - comment - 14 Dec 2018

Not good. Apart from the general issue with module link these now give
http://localhost:8888/installmulti/trunkgitnew/?nolangformat=1

avatar infograf768
infograf768 - comment - 14 Dec 2018

and no alternate at all.

avatar csthomas
csthomas - comment - 14 Dec 2018

About modules and generating alternative <link ...>.

Alternate URLs <link rel="alternate" ...> are special (they do not depend on cookies) and require additional fixes included in the languagefilter plugin.

			if (count($languages) > 1)
			{
				// Remove the sef from the default language if "Remove URL Language Code" is on
				if ($remove_default_prefix && isset($languages[$this->default_lang]) && $this->default_lang !== $this->current_lang)
				{
					$sef = $languages[$this->default_lang]->sef;
					$languages[$this->default_lang]->link = preg_replace("~/$sef(?:/|(?=[?#]|$))~", '/', $languages[$this->default_lang]->link, 1);
				}
				foreach ($languages as $i => &$language)
				{
					$doc->addHeadLink($server . $language->link, 'alternate', 'rel', array('hreflang' => $i));
				}
avatar csthomas
csthomas - comment - 14 Dec 2018

Alternate links without special patch will works too (there will be one more non cached redirect 301).

avatar csthomas
csthomas - comment - 14 Dec 2018

After I think about it more and more, I wonder that adding support for a particular NGINX configuration can generate more problems than benefits.

avatar infograf768
infograf768 - comment - 14 Dec 2018

TBH, I am also wondering about that, and as well about getting specific urls without the sef for the module's source link when default site language is concerned. A redirection is not such a big deal after all for crawlers.

The present code is quite stable and changing it may have unwanted results. Shall we just drop these patches (yours and mine)?

avatar csthomas
csthomas - comment - 14 Dec 2018

OK, I will remove support for NGINX (removing slash).

avatar infograf768
infograf768 - comment - 14 Dec 2018

Let's drop all. It's too much risk imho.

avatar joomla-cms-bot joomla-cms-bot - change - 14 Dec 2018
Category Modules Front End Plugins Libraries Modules Front End Plugins
avatar csthomas
csthomas - comment - 14 Dec 2018

I got lost a little, what does this PR do now.

I see a reason if I have a canonical page to my article /blog/14-subcategory/123-article.
Then I move my article to the different category 15-opinions and the new canonical URL will be /blog/15-opinions/123-article.

Open browser on outdated URL /blog/14-subcategory/123-article.

Before this PR mod_languages will generate URL to outdated URL /blog/14-subcategory/123-article
but after patch it will generate URL /blog/15-opinions/123-article.

avatar Giuse69
Giuse69 - comment - 14 Dec 2018

I would drop changes for specific NGIX situation but not for stripping def language tag from module, already alternate links do that properly, it is a different behavior that would be fine to have aligned

avatar csthomas
csthomas - comment - 14 Dec 2018

... already alternate links do that properly

Joomla can do this because alternative links are used by robots that do not use cookies.

BTW It is time to close it.

avatar csthomas csthomas - change - 14 Dec 2018
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2018-12-14 13:29:22
Closed_By csthomas
avatar csthomas csthomas - close - 14 Dec 2018

Add a Comment

Login with GitHub to post a comment