Apr 12, 2012

When not to use typoLink

For a long time I tell everybody to use typoLink to create links inside TYPO3.

A “go”:

$url = $this->cObj->typoLink_URL(array(
    'parameter' => $GLOBALS['TSFE']->id
));

A “no go”:

$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

But there is one case when you absolutely must not use typoLink to create the URL. It is when the URL points to the eID script. Why? Because there is no resolving of the speaking URL inside eID anyway. So it is a complete waste of time and memory to have something like /path/to/my/news/page/news/how-i-bought-a-car.html?eID=tx_myext_eid.

Just do it like this:

$url = t3lib_div::locationHeaderUrl('index.php?eID=tx_myext_eid').

That's the right way.

5 comments:

  1. eID is often used for AJAX requests and from that point of view you're absolutely right.
    But there might also be cases where eID puts out whole HTML-Pages. Those documents better have speaking URLs for the convenience of the users and ranking in search engines.

    ReplyDelete
  2. Probably the best in this case, it's to use RewriteRule for eID scripts on the level of .htaccess.

    ReplyDelete
  3. One should also point that for performance reason (when generating thousands of links), using typoLink might prove unfeasible.

    ReplyDelete
  4. Thanks this was really helpful to me.:)

    ReplyDelete
  5. tuzi gand
    @Dmitry Dulepov:-
    This wass a nice post which really help me a lot thnx in advance :) but i would like to know more about .htaccess and its benefits.Waiting for you valuable reply. Thank you againg

    ReplyDelete