MODX Community

LangRouter and PdoMenu home link error

Hello.

I’m working with multilingual site using LangRouter.

There is not reference to site_start context setting in the documentation: http://jako.github.io/LangRouter/usage/

I just realised that not using the site_start setting inside the context creates a 404 error when try to access to the main page of every context just typing domain.com/cultureKey/

Context: en
domain.com/en/ GOOD

Context: es
domain.com/es/ 404 ERROR

To avoid that error I’m including the site_start setting for every context.

But using PDOMenu to create the menu links, it makes the site_start page only point to domain.com/ no matter the context, all the other links are working fine.

any idea or advice to avoid this behaviour?
Thanks!

Hi @ysanmiguel, yeah each context needs a site_start so it knows what to load when a particular page isn’t specified.

I’m not sure exactly what you mean with pdoMenu… can you show your snippet call?

Thanks mate.

This is a very simple menu, where I can decide what Id’s display:

[[$menu-footer? &ids=7,8]]
In this specific case 7 is the site_start from a secondary context es

$menu-footer:

[[pdoMenu?
    &tplOuter=`@INLINE 
    <ul class="row footer-menu [[+classnames]]">
        [[+wrapper]]
    </ul>`
    &tpl=`@INLINE 
    <li class="col-6 md-col [[+classnames]]">
        <a class="nav-link text-center text-md-left" href="[[+link]]" [[+attributes]]>[[+menutitle]]</a>
    </li>`
    &resources=`[[+ids]]`
    &parents=`0`
    &parents=`[[*context_key]]`
]]

The problem is the link to ID 7 is pointing to domain.com/ not where it should domain.com/es/
ID 8 and any other ID I put on that resouce works fine, they all are pointing to domain.com/es/respective-page.html

Do you get the same result from both contexts? (assuming you’re trying to get the same resource id from the footer which exists on both)
Does calling it uncached change anything?
Also, I’m unfamiliar with a [[*context_key]] tag being used in the parents parameter. Normally that would be resource ids.

Yes I get the same result in both context but only with the pages that are set in the site_start.
let me explain you:

I got 2 context:

[[*context_key]] = web (default)
base_url: /
cultureKey: en
http_host: domain.com
site_start: 1
site_ur: {url_scheme}{http_host}{base_url}{cultureKey}/


[[*context_key]] = es
base_url: /
cultureKey: es
http_host: domain.com
site_start: 7
site_ur: {url_scheme}{http_host}{base_url}{cultureKey}/

I called my code to display the links:

For context web:

[[$menu-footer? &ids= 1,3 ]] (pages exist inside the context web)
output:
for ID1: <a class="nav-link text-center text-md-left" href="/">Home</a>

for ID 3: <a class="nav-link text-center text-md-left" href="page-two.html">Page Two</a>

For context es:

[[$menu-footer? &ids= 7,8 ]] (pages exist inside the context es)
output:
for ID 7: <a class="nav-link text-center text-md-left" href="/">Inicio</a>

for ID 8: <a class="nav-link text-center text-md-left" href="pagina-dos.html">Página Dos</a>


Here is where everything goes funny! :grin: :grin: :grin:

If change the site_start to 8 instead of the current one that is 7 on context es

[[*context_key]] = es
site_start: 8

for ID 7: <a class="nav-link text-center text-md-left" href="index.html">Inicio</a>

for ID 8: <a class="nav-link text-center text-md-left" href="/">Página Dos</a>

With this example you can see how site_start affects the output link, no matter the context.


Uncached is not doing anything different, unfortunately.

And [[*context_key]] as you see before is jut to filter the output for the current context, if I remove it it doesn’t affect the output.

Thanks mate for your time and help, I’m just clueless with this one, cheers!!!

Did you create a site_start Context Setting for each context at System (gear icon) -> Contexts -> “Create New”?

That will override the System Setting for that context.

Try adding an error_page setting to each context pointing at a dedicated 404 resource on each of those contexts.

Remove both the &parent parameters from your snippet call and add &context=`[[*context_key]]` instead.

Also it’s probably just a typo but make sure the context setting site_ur is actually site_url.

If it’s still not working. Add &showLog=`1` to the pdoMenu call to help you debug.
Also, go to the system settings for LangRouter and set debug to yes. You can then see exactly what’s happening with the routing in the error log.

Hello Bob.
The answer is Yes mate, I create the site_start from that place.
Thanks!

  • Well there was 2 &parent, one of them should be context='[[*context_key]]' my mistake!
    but the change didn’t do any good still the same.
  • Can’t delete &parent= 0 otherwise the default will be Current resource and not display any link!
  • the site_url is right written

Here the LangRouter Log:

OPENING / HOME PAGE

[2020-01-15 10:35:22] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 156) Unhandled request:
    REQUEST_URI:   /
    REDIRECT_URI:  
    QUERY_STRING:  
    q:             
    Context:       web
    Site start:    1
    [2020-01-15 10:35:22] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 173) contextmap: array(2) {
      ["en"]=>
      string(3) "web"
      ["es"]=>
      string(2) "es"
    }

   [2020-01-15 10:35:22] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 173) Detected culture key: string(2) "en"

  [2020-01-15 10:35:22] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 173) Detected context key: string(3) "web"

   [2020-01-15 10:35:22] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 156) Culture key not found in URI:
    REQUEST_URI:   /
    REDIRECT_URI:  
    QUERY_STRING:  
    q:             
    Context:       web
    Site start:    1
    [2020-01-15 10:35:22] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 185) Context switch to "web" was not valid.

OPENING /ES/ PAGE

[2020-01-15 10:36:01] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 156) Unhandled request:
REQUEST_URI:   /es/
REDIRECT_URI:  
QUERY_STRING:  q=es/
q:             es/
Context:       web
Site start:    1
[2020-01-15 10:36:01] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 173) contextmap: array(2) {
  ["en"]=>
  string(3) "web"
  ["es"]=>
  string(2) "es"
}

[2020-01-15 10:36:01] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 156) Culture key found in URI:
REQUEST_URI:   /
REDIRECT_URI:  
QUERY_STRING:  q=es/
q:             
Context:       es
Site start:    7

Any help please?
Don’t understand what is exactly happening!

Are you perchance including a resource that doesn’t belong to the current context?
Do a pdoMenu call without the &resource parameter and see what resources it has access to.

Using this PDO call:

[[pdoMenu?
    &tplOuter=`@INLINE 
    <ul class="row footer-menu [[+classnames]]">
        [[+wrapper]]
    </ul>`
    &tpl=`@INLINE 
    <li class="col-6 md-col [[+classnames]]">
        <a class="nav-link text-center text-md-left" href="[[+link]]" [[+attributes]]>[[+menutitle]]</a>
    </li>`
    &parents=`0`
    &showLog=`1`
]]

The output is:

<ul class="row footer-menu ">
            <li class="col-6 md-col first active">
            <a class="nav-link text-center text-md-left" href="/">Inicio</a>
        </li><li class="col-6 md-col last">
            <a class="nav-link text-center text-md-left" href="pagina-dos.html">Página Dos</a>
        </li>
        </ul>

Inicio : ID 7 is linked to: https://domain.com (witch is the site_start in context web)
Página Dos: ID 8 is linked to: https://domain.com/es/pagina-dos.html (that is the right URL)


Opening the ID 7 in context ES where site_start is 7
here the pdoMenu Log:

0.0029652: pdoTools loaded 0.0000169: xPDO query object created 0.0001090: Added selection of **modResource** : <small>id, type, contentType, pagetitle, longtitle, description, alias, alias_visible, link_attributes, published, pub_date, unpub_date, parent, isfolder, introtext, content, richtext, template, menuindex, searchable, cacheable, createdby, createdon, editedby, editedon, deleted, deletedon, deletedby, publishedon, publishedby, menutitle, donthit, privateweb, privatemgr, content_dispo, hidemenu, class_key, context_key, content_type, uri, uri_override, hide_children_in_tree, show_in_tree, properties</small> 0.0000138: Processed additional conditions 0.0001121: Added where condition: **modResource.published=1, modResource.hidemenu=0, modResource.deleted=0, modResource.context_key=es** 0.0000391: Sorted by **modResource.menuindex** , **ASC** 0.0002749: SQL prepared <small>"SELECT modResource.id, modResource.type, modResource.contentType, modResource.pagetitle, modResource.longtitle, modResource.description, modResource.alias, modResource.alias_visible, modResource.link_attributes, modResource.published, modResource.pub_date, modResource.unpub_date, modResource.parent, modResource.isfolder, modResource.introtext, modResource.content, modResource.richtext, modResource.template, modResource.menuindex, modResource.searchable, modResource.cacheable, modResource.createdby, modResource.createdon, modResource.editedby, modResource.editedon, modResource.deleted, modResource.deletedon, modResource.deletedby, modResource.publishedon, modResource.publishedby, modResource.menutitle, modResource.donthit, modResource.privateweb, modResource.privatemgr, modResource.content_dispo, modResource.hidemenu, modResource.class_key, modResource.context_key, modResource.content_type, modResource.uri, modResource.uri_override, modResource.hide_children_in_tree, modResource.show_in_tree, modResource.propertiesFROMmodx_site_contentASmodResourceWHERE (modResource.published= 1 ANDmodResource.hidemenu= 0 ANDmodResource.deleted= 0 ANDmodResource.context_key = 'es' ) ORDER BY modResource.menuindex ASC "</small> 0.0001040: SQL executed 0.0000169: Rows fetched 0.0000238: Returning raw data 0.0000041: Tree was built 0.0000520: Start template tree 0.0003400: Created inline "modChunk" with name "255fe54bb27144f7faa4163bf0b0bbae" 0.0005970: End template tree 0.0001380: Created inline "modChunk" with name "79f96860eab6354fd18b94d70541b82a" 0.0049551: **Total time** 12 582 912: **Memory usage**


And here the manager Error log:

[2020-01-17 12:06:17] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 158) Unhandled request:
REQUEST_URI:   /es/
REDIRECT_URI:  
QUERY_STRING:  q=es/
q:             es/
Context:       web
Site start:    1
[2020-01-17 12:06:17] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 175) contextmap: array(2) {
  ["en"]=>
  string(3) "web"
  ["es"]=>
  string(2) "es"
}

[2020-01-17 12:06:17] (ERROR in LangRouter @ /home/user/public_html/core/components/langrouter/model/langrouter/langrouter.class.php : 158) Culture key found in URI:
REQUEST_URI:   /
REDIRECT_URI:  
QUERY_STRING:  q=es/
q:             
Context:       es
Site start:    7

My Context Settings:

key: web
name: website

base_url: /
cultureKey: en
error_page: 9
http_host: domain.com
site_start: 1
site_url: {url_scheme}{http_host}{base_url}{cultureKey}/




key: es
name: Español

base_url: /
cultureKey: es
error_page: 10
http_host: domain.com
site_start: 7
site_url: {url_scheme}{http_host}{base_url}{cultureKey}/

Don’t understand where is the problem, into LangRouter or PdoMenu?
It only affect’s the page set as site_start

may be Mr. @jako can give us a hand?

What resource type is the resource 7? Is it a weblink?

If yes, it could be this issue (and the fix): https://github.com/bezumkin/pdoTools/pull/297

Hey mate, nice to see you. Thanks for “comming”.

No, they all are Resource Type: Document

The problem is with the site_start in each context, they both are pointing to domain.com not to domain.com/cultureKey/

  • The [[+menutitle]] in both context is right, one display Hone the other Inicio
  • If I link from one context to the other it works fine: For example from a page in web context link to the site_start in context es, the url is: domain.com/es/ what is good!

Any rules in your Apache .htaccess or nginx config file that may be conflicting?

Well good idea I thought might be this lines that I use to force all url to https.
I delete them but no change:

RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]

my .htaccess

RewriteEngine On
RewriteBase /

RewriteRule "/\.|^\.(?!well-known/)" - [F]

RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]

# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

# Block access to /assets/ folder
Options -Indexes

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 1 month"
</IfModule>

<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>

AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml

<ifModule mod_headers.c>
  Header unset ETag
</ifModule>
FileETag None

<ifModule mod_headers.c>
  Header unset Last-Modified
</ifModule>

<ifModule mod_headers.c>
    Header set Connection keep-alive
</ifModule>

Here is a brand new installation. with the same behaviour.
https://modx.ysanmiguel.com/

Friendly URL ON
.htaccess is the modx default.

Extras installed:
Babel, LangRouter and pdoToolspdoTools.

Context web:

base_url: /
cultureKey: en
error_page: 1
http_host: modx.ysanmiguel.com
site_start: 1
site_url: {url_scheme}{http_host}{base_url}{cultureKey}/

Context es:

base_url: /
cultureKey: es
error_page: 2
http_host: modx.ysanmiguel.com
site_start: 2
site_url: {url_scheme}{http_host}{base_url}{cultureKey}/

Error Log opening every page:

[2020-01-20 13:04:27] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 158) Unhandled request:
REQUEST_URI:   /
REDIRECT_URI:  
QUERY_STRING:  
q:             
Context:       web
Site start:    1
[2020-01-20 13:04:27] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 175) contextmap: array(2) {
  ["es"]=>
  string(2) "es"
  ["en"]=>
  string(3) "web"
}

[2020-01-20 13:04:27] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 175) Detected culture key: string(2) "en"

[2020-01-20 13:04:27] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 175) Detected context key: string(3) "web"

[2020-01-20 13:04:27] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 158) Culture key not found in URI:
REQUEST_URI:   /
REDIRECT_URI:  
QUERY_STRING:  
q:             
Context:       web
Site start:    1
[2020-01-20 13:04:27] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 187) Context switch to "web" was not valid.
[2020-01-20 13:04:41] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 158) Unhandled request:
REQUEST_URI:   /en/page-two.html
REDIRECT_URI:  
QUERY_STRING:  q=en/page-two.html
q:             en/page-two.html
Context:       web
Site start:    1
[2020-01-20 13:04:41] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 175) contextmap: array(2) {
  ["es"]=>
  string(2) "es"
  ["en"]=>
  string(3) "web"
}

[2020-01-20 13:04:41] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 158) Culture key found in URI:
REQUEST_URI:   /page-two.html
REDIRECT_URI:  
QUERY_STRING:  q=en/page-two.html
q:             page-two.html
Context:       web
Site start:    1
[2020-01-20 13:04:55] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 158) Unhandled request:
REQUEST_URI:   /es/
REDIRECT_URI:  
QUERY_STRING:  q=es/
q:             es/
Context:       web
Site start:    1
[2020-01-20 13:04:55] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 175) contextmap: array(2) {
  ["es"]=>
  string(2) "es"
  ["en"]=>
  string(3) "web"
}

[2020-01-20 13:04:55] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 158) Culture key found in URI:
REQUEST_URI:   /
REDIRECT_URI:  
QUERY_STRING:  q=es/
q:             
Context:       es
Site start:    2
[2020-01-20 13:06:11] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 158) Unhandled request:
REQUEST_URI:   /es/pagina-dos.html
REDIRECT_URI:  
QUERY_STRING:  q=es/pagina-dos.html
q:             es/pagina-dos.html
Context:       web
Site start:    1
[2020-01-20 13:06:11] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 175) contextmap: array(2) {
  ["es"]=>
  string(2) "es"
  ["en"]=>
  string(3) "web"
}

[2020-01-20 13:06:11] (ERROR in LangRouter @ /home/yuser/modx/core/components/langrouter/model/langrouter/langrouter.class.php : 158) Culture key found in URI:
REQUEST_URI:   /pagina-dos.html
REDIRECT_URI:  
QUERY_STRING:  q=es/pagina-dos.html
q:             pagina-dos.html
Context:       es
Site start:    2

Have you got the LangRouter system settings filled out, or just using the Babel ones? If not, try filling them out.
If still an issue, add a context with the context_key en and try using that instead of web. It shouldn’t but that’s how all mine get set up and they work.

Mate try everything and the only way that this works fine is removing the site_start value from the context.
the only problem is that domain.com/en/ or domain.com/es/ are error pages, but if I add index.html it works.
this is nightmare.
Do you have any simple setup backup that I can try in my hosting? just to check, may be it’s a php setting or something.

Looks like the problem is just me! :rofl: :rofl: F***!
Cheers!

Well one of the ways that it’s “working” is:

context web:

base_url: /
cultureKey: en
error_page: 9
home_page: 1
http_host: domain.com
site_start: 1
site_url: {url_scheme}{http_host}{base_url}{cultureKey}/

Context es:

base_url: /
cultureKey: es
error_page: 10
home_page: 7
http_host: domain.com
site_start:    (field empty)
site_url: {url_scheme}{http_host}{base_url}{cultureKey}/

The setting home_page is to link the menu logo to the homepage of every context:

<a class="navbar-brand" href="[[~[[++home_page]]? &scheme=full]]"><img src="[[++menu_logo:pthumb=h=35]]" alt="[[+site_name]]" /></a>

I normally use the site_start in this case but can’t fill it in both context.

The only oproblem with this set up is:

  1. the domain.com/es/ is an error page.
  2. domain.com/en/ and domain.com and domain.com/es/index.html exist as different pages, I think that affect SEO