Search code examples
typo3realurltx-newstypo3-8.x

TYPO3 realurl and tx_news, use title as entire path-segment


I migrated a wordpress website, using the Yoast SEO plugin, to TYPO3 and the news articles have URL's that use only the domain and the title;

## example
http://example.com/news-title/
  • I work with TYPO3 v8.7.10, tx_news 6.3.0 and realurl 2.3.1

  • I know how to hide the controller and action name by using fixedPostVars as described in docs.typo3.org

  • of course I can do a permanant redirect with .htaccess

  • I know the trick in the configuration with user_encodeSpURL_postProc and user_decodeSpURL_preProc but there I need at least one directory ...

does anybody knows any other option ?


Solution

  • I propose this solution

    1) Skip not needed arguments

    By using the following setting

    plugin.tx_news {
            settings {
                    link {
                            skipControllerAndAction = 1
                    }
            }
    }
    

    the links don't include the controller and action anymore. I prefer to use this instead of removing it in realurl because of less magic in realurl.

    2.) Render the single view on the homepage

    Just for clarification: As homepage is the meant the 1st page.

    [globalVar = GP:tx_news_pi1|news > 0] && [globalVar = TSFE:id = HOMEPAGE-ID]
      lib.news = USER
      lib.news {
                    userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
                    pluginName = Pi1
                    vendorName = GeorgRinger
                    extensionName = News
                    controller = News
                    settings =< plugin.tx_news.settings
                    persistence =< plugin.tx_news.persistence
                    view =< plugin.tx_news.view
                    action = detail
                    switchableControllerActions.News.1 = detail
      }
      page.10 < lib.news
    [end]
    

    This is just a proof of concept as the final integration depends on how render your templates & content. You could also remove the page.10 < lib.news and check the variable lib.news in your content or you assign it to the variables and check that in the templates.