0
votes

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:

    '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:

http://www.mypage.com/blog/artikel/asdasd ---> works fine. Goes to page 404.

http://www.mypage.com/blog/artikel/whatever/whateveragain ---> works fine. Goes to page 404.

http://www.mypage.com/blog/artikel/whatever ---> will NOT redirect to 404. I get "No news_id was given."

1

1 Answers

1
votes

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.

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.

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:

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)

on the your page 57 add extension teamplate with Template module and in setup use condition to check if param exists:

[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]