Uploaded image for project: 'Magnolia Multisite Module'
  1. Magnolia Multisite Module
  2. MULTISITE-109

Incorrect i18n links with subsites

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Neutral Neutral
    • 2.1.2
    • None
    • Global Maintenance 1, Global Maintenance 2
    • 8

      Steps to reproduce (generic - specific below)

      •  Create the following pages with whatever content:
        /main-site
        /main-site-sub
        /main-site-sub/whatever
      • Then create two site definitions with the same (Overlapping) domain and with an empty URI prefix mapping to /main-site and a /sub URI prefix mapping to /main-site-sub. Enable at least two locales for the main-site-sub site.
      • Add enough content/FTL/etc. to your templates to output some cmsfn.link() values and also the cmsfn.localizedLinks() method. For example, within the /main-site-sub make sure you have a link to the "whatever" page.
      • Navigate to the sub site by going to http://your-mapped-domain/sub.
        Note all links are fine when browsing the default locale.
        Change to the non-default locale.
        Note that the links to the "whatever" page are now prepending /main-site as if it is a cross-site request.

      Steps to reproduce (Specific for travel demo)

      •  Create the following pages with whatever content: (/travel should already exists)/travel-test (travel home template)
        /travel-test/test-page (travel standard template)
        Add content for en and de locales. Publish both pages.See screenshot step1 for example.
      •  Duplicate travel site definition (mine is called travel0 by default) with the same (overlapping) domain and with a /sub URI prefix mapping to /travel-test. See screenshot step2 for example.
        Enable at least two locales for the main-site-sub site (should be by default in travel site def).
        Publish site definiton.
      • Navigate to the sub site by going to https://travel-demo.magnolia-cms.com/sub and https://travel-demo.magnolia-cms.com/sub/test-page.
        Note all links are fine when browsing the default locale.
        Change to the non-default locale by selecting german at the top right.
        Note that the links to the "test-page" page are now prepending /travel0 as if it is a cross-site request. Ex. https://travel-demo.magnolia-cms.com/travel0/de/sub/test-page
        See screenshot3 and screenshot4 for examples.

      Expected results

      For the site definition to not be prepending to the url. To see a url like this: https://travel-demo.magnolia-cms.com/de/sub/test-page

      Actual results

      Url like: https://travel-demo.magnolia-cms.com/travel0/de/sub/test-page with site definition prepended to url

      Development notes

      Partner traced the above behavior to the following code within info.magnolia.multisite.DomainNamePathTransformer:

       protected String applyI18n(String linkStr, Site targetSite, Link uuidLink, int currentSiteHandlePrefixLen) {
          final String i18nLinkStr;
          if (targetSite == null || targetSite.getI18n() == null) {
              i18nLinkStr = I18nContentSupportFactory.getI18nSupport().toI18NURI(linkStr);
          } else {
              i18nLinkStr = targetSite.getI18n().toI18NURI(linkStr);
          }
      
          if (!i18nLinkStr.equals(linkStr) && isSubsite(targetSite, uuidLink.getPath(), uuidLink.getWorkspace(), currentSiteHandlePrefixLen)) {
              return "/" + targetSite.getName() + i18nLinkStr;
          }
          return i18nLinkStr;
      }

       
      Note the last if condition that uses the isSubsite() method and then outputs the link w/the target site name prefixed. The isSubsite() method has logic that is looking for some overlapping URI prefixes. In the above we have overlapping URI prefixes, as in the two sites have the same start:

      /main-site
      /main-site-sub

      This triggers the above logic, thought to be incorrect because links are not going cross site.

      Workaround 

      A stupid fix is to rename your pages and handle prefixes:

      **/main-site
      /main-subsite-sub

      Now they don't have the same "start" and so Magnolia doesn't match them as "subsites" whatever that means.

      In practice Partner is finding this is not a good solution, customer has many such situations where a single domain has many small microsites / landing pages / etc. which need their own site definition for custom theming, i18n, etc. and we've already hit enough situations where getting all the naming right is going to be near impossible without constant developer support.

      Partner is currently deploying a workaround that removes these lines:

       if (!i18nLinkStr.equals(linkStr) && isSubsite(targetSite, uuidLink.getPath(), uuidLink.getWorkspace(), currentSiteHandlePrefixLen)) {
          return "/" + targetSite.getName() + i18nLinkStr;
      }

      but they don't really know if there will be some negative impact elsewhere.

       

        Acceptance criteria

          1. screenshot3.png
            screenshot3.png
            90 kB
          2. screenshot4.png
            screenshot4.png
            105 kB
          3. step1.png
            step1.png
            67 kB
          4. step2.png
            step2.png
            128 kB

              jsimak Jaroslav Simak
              lstaniorski Leah Staniorski
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD

                    Estimated:
                    Original Estimate - Not Specified
                    Not Specified
                    Remaining:
                    Remaining Estimate - Not Specified
                    Not Specified
                    Logged:
                    Time Spent - 3h
                    3h