Jump to content

[SOLVED] Problem with trailing slash on domain's home pages in a multilanguage and multisite installation (using Soma's Module)


HakeshDigital
 Share

Recommended Posts

Hello everybody. This is my first topic on the forum.

ProcessWire version 3.0.225
Multisite version 0.1.2

I am using the @Soma's multisite module with multilanguage support (for 4 languages) and is working for my basic requirements. My default language is spanish and the root page (with home template) has the respective names for every language (es, en, it, pt). I am having trouble trying to make the trailing slashes to work for the main root parents (websites). My urls work as expected except in one situation:

https://domain.tld/es/ -> loads the spanish (default) page
http://domain.tld -> redirects to the spanish (default) page
https://domain.tld -> redirects to the spanish (default) page
https://domain.tld/ -> redirects to the spanish (default) page

https://domain.tld/es -> brings Error 404

If the url contains the language without trailing slash, it fails... Even when the template is configured to work only with trailing slash, and even defining different rules in the root's folder .htaccess without effect.

RewriteCond %{REQUEST_URI} ^(.*)/([a-z]{2})$
RewriteRule ^(.*/)(es|en|it|pt)$ $1$2/ [R=301,L]
RewriteRule ^(.*/)es$ ^(.*/)es/ [R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+(?:es|en|it|pt))$ /$1/ [L,R=301]
RewriteCond %{REQUEST_URI} ^/([a-z]{2})/
RewriteRule ^ - [E=LANG:%1]

RewriteCond %{ENV:LANG} !^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]

Can anybody be so kind to explain me what to do with this issue? Thanks in advance.

PS: I tried to migrate to @kixe multisite module but couldn't make hookable the LanguageSupportPageNames::getPagePath(). I still don't know how to achieve such task. Maybe wih this module I could solve the issue, according to the readme file.

Edited by HakeshDigital
SOLVED
Link to comment
Share on other sites

Hi @HakeshDigital

Does it work if you remove, or comment out, the indicated line from your .htaccess file...

RewriteCond %{REQUEST_URI} ^(.*)/([a-z]{2})$
RewriteRule ^(.*/)(es|en|it|pt)$ $1$2/ [R=301,L]
RewriteRule ^(.*/)es$ ^(.*/)es/ [R=301]  ## <<< Remove this line, or comment out with # at the start.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+(?:es|en|it|pt))$ /$1/ [L,R=301]
RewriteCond %{REQUEST_URI} ^/([a-z]{2})/
RewriteRule ^ - [E=LANG:%1]

RewriteCond %{ENV:LANG} !^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]

...?
 

Link to comment
Share on other sites

10 hours ago, netcarver said:

Does it work if you remove, or comment out, the indicated line from your .htaccess file...

 

Hi @netcarver. Thanks for your interest. I am not using any of these lines. I shared them as an example of the multiple strategies I have already tested. Somehow doesn't matter what I do, something is happening inside PW. According to some browseo.com tests, the pages are doing multiple redirects:

Redirects found https://domain.tld/
⇓
/es/www_domain_tld/ (301 Moved Permanently) [I use this page names on the apex domains so the subdomains can work.]
⇓
https://domain.tld/es/ (301 Moved Permanently)

---

https://domain.tld/es

Response-Code    404 (Not Found)

 

I am having a serious SEO impact doubt to this problem. And I started this multisite as an SEO platform ? for hundreds of domains.

Another issue is when I share a homepage link on whatsapp... If I paste:

https://domain.tld/es/

Whatsapp is not able to retrieve the page metadata. I have to add a faux parameter to make it show the page title, image and description:

https://domain.tld/es/?foo

---

➜ HOW CAN I INSTALL THE ALTERNATIVE MULTISITE MODULE? ??

Do you know how to make LanguageSupportPageNames::getPagePath() hookable, so I can migrate to the other Multisite module? I contacted @kixe without success.
According to this https://github.com/kixe/Multisite/blob/master/README.md, that module has everything I am looking for:

? Do not worry about page naming. The root page is defined via ID.
? FULL multilanguage support
? take in account $template->slashUrl settings
? take in account LanguageSupportPageNames::useHomeSegment settings
? Throws exception in case of misconfiguration
? Access of pages residing inside a MultisitePageTree for other domains other than the corresponding domain is disallowed. (404)
? Pages inside a MultisitePageTree accessible only via url based on the corresponding domain. 404 instead of unexpected redirects. [This is making some of my domains not to appear on Google]
Page paths are set via hook in Page::path() and LanguageSupportPageNames::getPagePath() instead of modifying the return of Page::render()
? Crosslink support via the RTE (CK Editor) Link plugin. [I invented a "shortcodes" system to avoid this problem, but I'w prefer the standard methodology for my users]
? Page view links in admin with correctly modified urls. For the branch related to calling domain only. [This is Awesome... My stats are all indicating /es/ /en/ and so on... I can not see wht domains are the most visited and the worst part is to undesrstand the thousands of error logs for 404 pages]

Hope you or someone else can guide me on this. Thanks in advance. 

Link to comment
Share on other sites

After many many many fails, I've finally found a solution.

Now the .htaccess in the root folder of the Processwire installation contains this ?️ magic rule, in the first part of the 13c Section:

RedirectMatch 302 ^/(.*)(es|en|it|pt)$ /$1/$2/?lang=$2

Also, this can be set as a permanent redirect:

RedirectMatch 301 ^/(.*)(es|en|it|pt)$ /$1/$2/?lang=$2
Link to comment
Share on other sites

  • HakeshDigital changed the title to [SOLVED] Problem with trailing slash on domain's home pages in a multilanguage and multisite installation (using Soma's Module)
  • 3 weeks later...

That rule was in conflict with native admin urls so I had to change it and use this way:

<IfModule mod_rewrite.c>

  RewriteEngine On
  RedirectMatch 302 ^(.*)/(en|it|pt)$ /$1/$2/?lang=$2
  
  # ...

Hope this help someone else in the near future.

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...