简体   繁体   English

TYPO3:RealURL + tt_news + 404不起作用

[英]TYPO3: RealURL + tt_news + 404 doesnt work

I wanted to give a special URL to the page (id=57) where the SINGLE view of tt_news is, so I used this to configure RealURL: 我想给tt_news的SINGLE视图所在的页面(id = 57)提供一个特殊的URL,所以我用它来配置RealURL:

    'fixedPostVars' => array(
        '57' => array(
            array(
                'GETvar' => 'tx_ttnews[tt_news]',
                'lookUpTable' => array(
                    'table' => 'tt_news',
                    'id_field' => 'uid',
                    'alias_field' => 'title',
                    'addWhereClause' => ' AND NOT deleted',
                    'useUniqueCache' => 1,
                    'useUniqueCache_conf' => array(
                        'strtolower' => 1,
                        'spaceCharacter' => '-',
                    ),
                ),
            ),
        ),
    ),

The problem is that the redirect in 404 wont work: 问题在于404中的重定向无法正常工作:

http://www.mypage.com/blog/artikel/asdasd ---> works fine. http://www.mypage.com/blog/artikel/asdasd --->效果很好。 Goes to page 404. 转到第404页。

http://www.mypage.com/blog/artikel/whatever/whateveragain ---> works fine. http://www.mypage.com/blog/artikel/whatever/whateveragain --->效果很好。 Goes to page 404. 转到第404页。

http://www.mypage.com/blog/artikel/whatever ---> will NOT redirect to 404. I get "No news_id was given." http://www.mypage.com/blog/artikel/无论如何--->都不会重定向到404。我收到“未提供news_id”。

That's normal for TYPO3 that page exists and contains a plugin, so it can't be considered as not existing it doesn't care that the extension didn't get all required params. 对于TYPO3 ,该页面存在并且包含一个插件是很正常的,因此不能将其视为不存在,它不在乎扩展没有获取所有必需的参数。

There two solution, one which I would recommend is writing small extension which will run at the beginning of page rendering process, will check if parameter exists AND if it points the existing and not disabled tt_news record, in other case it should return fully qualified 404 status and redirect to your 404 page - this will be good for purposes. 有两种解决方案,我建议编写一个小扩展名,该扩展名将在页面渲染过程开始时运行,它将检查参数是否存在以及是否指向现有且未禁用的tt_news记录,否则应返回完全合格的404。状态并重定向到您的404页面-这对于而言将非常

function main($content, $conf) {

    $newsParams = t3lib_div::_GET('tx_ttnews');
    if (is_array($newsParams) && intval($newsParams['tt_news']) > 0) {
        $foundItems = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'tt_news', 'deleted=0 AND hidden=0 AND uid=' . intval($newsParams['tt_news']));

        if (count($foundItems) == 1) {
            return null; // if news exists and is available - return null
        }
    }

    // If above condition aren't met, set redirect header
    // return null after that to avoid futher code processing

    header('Location: http://yourdomain.tld/404.html');
    return null;

}

In TypoScript only on page=57 add this line: 仅在TypoScript页面= 57上添加以下行:

page.1 < plugin.tx_yourext_pi1

Other solution 其他解决方案

is much more simpler, it's just to check if param in URL required for SINGLE view: &tx_ttnews[tt_news]=123 exists and is greater than 0 and if not just add redirect tag to the page's <head> section (writing just from top of my head, so debbug it yourself, pls) 更加简单,它只是检查SINGLE视图所需的URL中的参数:&tx_ttnews [tt_news] = 123是否存在且大于0,并且不只是将重定向标记添加到页面的<head>部分(仅从顶部开始编写)我的头,所以自己调试吧,请)

on the your page 57 add extension teamplate with Template module and in setup use condition to check if param exists: 在您的页面57添加带有Template模块的extension teamplate ,并在设置使用条件下检查参数是否存在:

[globalVar = GP:tx_ttnews|tt_news < 1]
  page.headerData.1 = TEXT
  page.headerData.1.value = <meta http-equiv="refresh" content="0;url=http://www.mypage.com/404">
[global]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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