简体   繁体   中英

Issue with realurl, redirect and caching in TYPO3

This error occures in TYPO3 7.6.10 with a piBase extension and realurl 2.0.15:

In this extension, I'm checking for a GET parameter, eg a country. If this parameter is not provided, I redirect to the same page, with default country as parameter:

if(!$this->piVars['country']) {
  $this->piVars['country'] = 'germany';
  \TYPO3\CMS\Core\Utility\HttpUtility::redirect($this->pi_linkTP_keepPIvars_url(array(), true), \TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_303);
}

That means, the visitor eg calls url www.mypage.com/list/ and is redirected to www.mypage.com/list/germany/

This works fine, but after some time passes and some visitors were an the page, the redirect stopped working. When opening www.mypage.com/list/ in the browser, the page is displayed for some country (not the default one, eg for country "france"). That means, TYPO3 creates on page www.mypage.com/list/france/ a cache entry for page www.mypage.com/list/, but for this url, a cache entry should've never been created, because of the redirect.

I can reproduce this error by setting caching time of the page to 1 minute. Then I wait one minute, then loading the url www.mypage.com/list/france/. Now, when opening www.mypage.com/list/, there is no redirect and france is shown.

When disabling realurl (or just removing parameter "country" from realurl configuration), this error doesn't occur.

TYPO3 stores in cache so-called "versions" of a page with corresponding cHash and additionaly a version without cHash - kind of a "default" page.

If something wrong happens, when cHash is validated by the core, it gets rejected and page is generated, using provided params in url.

In case of very first hit (cache is empty) and a wrong cHash page is generated, using the params from URL, but due to a wrong cHash this version is then understood as "default" and stored in cache.

The real reason you need to find in your code. It can be a wrong combination of RealURL configuration and code. Eg enableCHashCache is set to false in RealURL configuration, but link is provided w/out cHash.

I can't tell you the exact reason, but you can check it different ways:

  1. Set FE - pageNotFoundOnCHashError at Install Tool and check if 404 error happens, when you visit www.mypage.com/list/france/

  2. Disable RealURL and visit different versions of a page with different country values - does cHash change for different countries or stays the same?

  3. Check the url, generated by pi_linkTP_keepPIvars_url() with and without RealURL. Does it contain cHash ?

The problem is described here: realurl generates entries without cHash

Since version 2.0.15, realurl doesn't calculate the cHash parameter for links, which are accessed directly and which need a cHash parameter to show the right cached contents, like detail pages of a record.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM