by
back

Follow shortcuts or external urls in typo3 menus

In typo3 you can configure a page to be a shortcut to another page or to link to an external URL. The problem is, that typo3 generates a unique url for each page. In the case of a page with the type "shortcut", typo3 shows the content of the target page but the url in the browser will alwayas be the one of the shortcut-page.

If you configure a page as "Link to External URL", then typo3 will redirect the user with a 302 http statuscode to the target url.

Both solutions are not very good from the seo viewpoint. To avoid duplicate page content on different urls and unnecessary redirects we have write some typoscript.

Normally a menu with typoscript would look like

lib.menu = HMENU
lib.menu {
  1 = TMENU
  1.wrap = <ul>|</ul>
  1.NO {
    wrapItemAndSub=<li>|</li>
    stdWrap.htmlSpecialChars = 1
  }
}

To directly show the url from the target-page or the external url, we can overwrite the stdWrap.cObject with a CASE condition:

lib.menu = HMENU
lib.menu {
  1 = TMENU
  1.wrap = <ul>|</ul>
  1.NO {
    doNotLinkIt = 1
    wrapItemAndSub = <li>|</li>
    stdWrap.cObject = CASE
    stdWrap.cObject {
      key.field = doktype
      default = TEXT
      default {
        typolink.parameter.field = uid
        field = title
        stdWrap.htmlSpecialChars = 1
      }
      # pagetype shortcut
      4 = TEXT
      4 {
        field = title
        typolink.parameter.field = shortcut
      }
      # page typo3 external url
      3 = TEXT
      3 {
        field = title
        typolink.parameter.field = url
        typolink.extTarget.field = target
      }
    }
  }
}

The result for a normal page will be the same but the shortcut and the external url will have the right urls without duplicate page content or redirects.



comments powered by Disqus