0

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."

Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189

1 Answers1

1

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]
biesior
  • 55,576
  • 10
  • 125
  • 182
  • Heh, of course I wrote bad sample the condition should be reverse! (check edited condition) – biesior Jul 21 '12 at 21:40
  • The second solution works allright, but its quite inelegant, as you see a flash of "No news ID given". I have no idea how to build the extension you mentioned on the 1st case. – Enrique Moreno Tent Jul 24 '12 at 00:56
  • The fastest way is to use http://typo3.org/extensions/repository/view/kickstarter - create a new ext and add a FE plugin in it. It's only job is to check if there is parameter `&tx_ttnews[tt_news]` and optionally you can also check if news given in it exists in database. Otherwise you'll need just to redirect to another page. later you can just add it on the page 57 via TS: `page.1 < plugin.tx_yourext_pi1` – biesior Jul 24 '12 at 08:04
  • Sorry I expressed myself badly. I do know how to make extension with kickstarter, what I dont know is how to check the condition you mentioned. I've only built extensions using Typoscript and not PHP until now. – Enrique Moreno Tent Jul 24 '12 at 08:10
  • kickstarter is `click-click`tool, so you have to install it and play a while, soon you'll create small extension with only one fe plugin in it. There will be a class something like `class.tx_yourext_pi1.php` - so if you'll install the extension and will place it with TS as I showed in previous comment TYPO3 will call main() method on every page load... Use `t3lib_div::_GP` to fetch url's params - http://typo3.org/api/typo3/classt3lib__div.html#a1645ccd6b4e63b9ac75e3020b67cd8c5 (don't use common $_GET !) and perform common PHP `if` comparrision – biesior Jul 24 '12 at 08:19
  • As said, I already know kickstarter. the problem is that I know ZERO of t3lib. i have no idea how to check url parameters, make redirects or check with the database to compare results. – Enrique Moreno Tent Jul 24 '12 at 08:29
  • Let's deal: make any plugin, and make sure it's working, later I will write a methods body for that task – biesior Jul 24 '12 at 08:30
  • The plugin is ready and working. I'll wait for your method. Thanks. – Enrique Moreno Tent Jul 24 '12 at 08:51
  • Shouldnt I add "header("HTTP/1.0 404 Not Found");" to avoid Google indexation? also, is there a way to redirect using the id of the page (in case I change my Speaking URLs later)? – Enrique Moreno Tent Jul 24 '12 at 10:59
  • Ok, thanks that worked good. I'm still not sure if the way of handling the redirect is the best, but at least I get the behaviour I wanted. – Enrique Moreno Tent Jul 24 '12 at 17:58
  • @Dbugger , yes adding 404 header and building link dinamicaly is the best option, I sent you simplest (imho) solution to get it working, however there's always some field to make it better. – biesior Jul 24 '12 at 18:48