User tests: Successful: Unsuccessful:
Pull Request for Issue #23209 and #23144
sef
from URL when "Remove URL Language Code" is set to ON in the language filter plugin.sef
./en/
to /en
/en/
:
/en
/en
(remove trailing slash)Multilingual webisite with associations.
Issues fixed.
??
Status | New | ⇒ | Pending |
Category | ⇒ | Modules Front End Plugins |
Labels |
Added:
?
|
Fixed
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
joomla-cms/modules/mod_languages/helper.php
Line 141 in 937d938
Itemid
.
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.
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?"?
@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:
joomla-cms/plugins/system/languagefilter/languagefilter.php
Lines 290 to 312 in 8a40f58
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.
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.
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
?format=feed&type=atom
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
@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.
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 /
.
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.
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.
NOTE: the cookie deals with the language code (en-GB), not the sef.
OK, there is two issues:
<link href="http://localhost:8888/installmulti/trunkgitnew/en" rel="alternate" hreflang="en-GB" />
I should remove /en
.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.βenβ is removed ok when Add Suffix to Url is set to No
/en is removed ok when Add Suffix to Url is set to No.
In my dev site is stay. Hmm?
Category | Modules Front End Plugins | ⇒ | Libraries Modules Front End Plugins |
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.
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.
This changes probably also break something, I'm working on two different versions.
.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
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:
/fr
/
.you are right.
Not good. Apart from the general issue with module link these now give
http://localhost:8888/installmulti/trunkgitnew/?nolangformat=1
and no alternate at all.
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));
}
Alternate links without special patch will works too (there will be one more non cached redirect 301).
After I think about it more and more, I wonder that adding support for a particular NGINX configuration can generate more problems than benefits.
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)?
OK, I will remove support for NGINX (removing slash).
Let's drop all. It's too much risk imho.
Category | Modules Front End Plugins Libraries | ⇒ | Modules Front End Plugins |
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
.
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
... 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.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-12-14 13:29:22 |
Closed_By | ⇒ | csthomas |
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
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.
Question btw:
Never heard about routing an ampersand. What is it supposed to do? Any doc on this?
$language->link = JRoute::_('&');