Feeds:
RSS
Atom

This a part two of the “RealURL made easy” series. In the first part we reviewed how url is constructed using RealURL and saw what are main configuration directives. This part will show practical steps to create a good RealURL configuration. The next (3rd) part will teach you some neat configuration tricks. But first we have to create the configuration.

From RealURL perspective all installations can be divided into to groups: single-domain tree and multi-domain tree. Single domain tree is the simplest and we already saw how to configure single domains for RealURL using _DEFAULT keyword.
Multi-domain configuration is more complex. Typically sites in a multi-domain setup share the same set of preVars and postVarSets. fixedPostVars (if used at all) are different because fixedPostVars should be specified for the specific page (this is covered in part 1). Therefore we will concentrate on this typical case here.
The steps for setting up multi-domain RealURL configuration are:

  • create a prototype for configuration
  • collect all domain names and root page id values
  • configure main domains
  • efficiently configure aliased domains 

Creating configuration prototype

Firsts, we create a common base for all domains. As shown in part 1, we do it in the separate file.

The prototype is created as variable, which contains all properties common for all domains. The variable should have tx_realurl_ prefix to avoid conflicts with any other variables in the system:

<?php
$tx_realurl_config = array(
    'init' => array(
        'enableCHashCache' => true,
        'appendMissingSlash' => 'ifNotFile',
        'enableUrlDecodeCache' => true,
        'enableUrlDecodeCache' => true,
        'emptyUrlReturnValue' => '/',
    ),
    'preVars' => array(
    ),
    'postVarSets' => array(
        '_DEFAULT' => array(
        ),
    ),
    'pagePath' => array(
        'type' => 'user',
        'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
        'spaceCharacter' => '-',
        'languageGetVar' => 'L',
        'expireDays' => 3,
    ),
);
?>

Let's see what we have here. init section enables cHash processing. This is necessary if you use extensions like tt_news, whose output depends on the URL parameters. For more details see “Linking properly in your TYPO3 code” article.

Next there is appendMissingSlash option. This will append slash to the end of generated URL if the last segment does not look like a file. It is not required but makes URL look better for users.

Next two options enable caches. This significally improves RealURL performance.
The last option in init section sets the value of “empty” URL. Usually URL is empty when it refers to home page.

Next two sections are empty in our ptototype but you can add something there as was described in part 1 of these series. We will also see some examples in part 3 of these series.

The last section (pagePath) seldomly change. Sometimes people change the value of spaceCharacter option to underscore character. Notice that value of languageGetVar should not be changed.

expireDays sets expiration value for cache entries if page is moved or renamed. RealURL will continue to accept old path to page for these amount of days and redirect to a new address. This is very useful for users who bookmarked pages. Search engines (like Google) will also notice a change and properly update their index.

Creating configuration for domains

Next we collect domain names and corresponding page id values. If one page shares more than one domain, we will voluntary choose one domain as main and we will treat others as aliased domains.

The following code goes before the closing PHP tag in the file:

$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(
    'www.domain1.tld' => $tx_realurl_config,
    'domain1.tld' => 'www.domain1.tld',
    'www.domain2.tld' => $tx_realurl_config,
    'domain1.tld' => 'www.domain2.tld',
);

Notice how main and aliased domains are configured. Main domains have full configuration and aliased just point to main domains. This has two advantages over separate configuration:

  • saves PHP memory
  • ensures that aliased domain always have the same configuration as main domain

You will be surprised but we are almost done! The only thing left is to specify proper root page id values.

Specifying rootpage id values

Specifying root page id values is necessary in multidomain setup. Otherwise RealURL will not be able to trace the path and resolve it to page id. We do it very easily. We add the following code after previous code:

$TYPO3_CONF_VARS['EXTCONF']['realurl']['www.domain1.tld']['pagePath']['rootpage_id'] = 123;
$TYPO3_CONF_VARS['EXTCONF']['realurl']['www.domain2.tld']['pagePath']['rootpage_id'] = 456;

Last final cosmetic step is to unset $tx_realurl_config because it is not longer needed:

unset($tx_realurl_config);

That's all. You now have proper multi-domain setup for RealURL.

What you did not know about _DEFAULT

There is one important issue with using _DEFAULT in multi-domain environment.
When RealURL searches for domains, it does walks domains in the configuration sequentally until the first match. _DEFAULT matches always. It means that if any domain is placed after _DEFAULT, it will never be reached. Remember that! But better avoid using _DEFAULT at all in multi-domain configuration.

Conclusion

In this part we saw how easy it is to create a working configuration for RealURL in multi-domain environment. In the next article we will talk more about preVars and postVarSets and see how to make them better.

Like it? Then bookmark it! digg.comdel.icio.usgoogle.comMyLink.deYahooMyWebTechnoratiFurllive.comnetscapeTagThatWebnews

11 Comments

  1. on Tuesday, 10-06-08 15:36 Jb
    Thank you for this great tutorial :)
    I'm glad your Internet connection is back !
    And a big thank to you for sharing your TYPO3 knowledge :)
  2. on Wednesday, 11-06-08 12:48 Ph
    Thank you for this great article!
    But here is a question:
    Automatic serialized configuration is good or bad? Does it really faster? or it doesen't matter? (0.1ms vs 0.01ms for example)
  3. on Thursday, 12-06-08 15:04 Dmitry Dulepov
    Ph, serialized - yes, it is much faster. Imagine that 1000 visitors visit the page at the same time. 0.1 vs 0.01 matters a lot in this case.

    The difference here is PHP parsing vs data parsing. Data parsing is faster.
  4. on Thursday, 12-06-08 20:21 Ph
    So the last paragraph of last part of the tuturial will be "and now you can serialize configuration for maximum performance"?
  5. on Sunday, 15-06-08 20:41 Thomas
    In the first box you used 'enableUrlDecodeCache' two times. Did you mean 'enableUrlEncodeCache'?

    Whats going on with the 'enableUrlEncodeHash'-param. i've found in some example configurations?
  6. on Sunday, 15-06-08 21:00 Dmitry Dulepov
    Thomas, yes, it should be enableUrlDecodeCache. My mistake, I'll fix it next week.

    enableUrlEncodeHash does not exist.

    Ph, yes, that will defintely improve performance.
  7. on Monday, 30-06-08 15:30 Thorsten
    thanks for the great tutorial! it seems that I start to understand what I do with realurl at last...

    but i have one issue, I'm not sure if you encountered it before:
    I defined the $tx_realurl_config array variable and try to fill that in the domain specific arrays. but realurl does not fetch this configuration what leads to the URL patch just being the page IDs. looking in the BE info area, speaking url management -> configuration, I get an error saying "Passed variable is not an array or object" and the configuration is empty. when dumping $tx_realurl_config i get a working config set though.

    any idea what this might be?

    i use a typo3 4.1.1 and realurl 1.4.0 in a multi-domain enviroment. no _DEFAULT set!

    thanks a lot!
  8. on Monday, 30-06-08 16:51 Thorsten
    me again... i've been through some testing and it seems that the missing _DEFAULT value leads to this error. may that be an indicator to a broken domain record configuration?
  9. on Wednesday, 02-07-08 11:07 Markus
    Thank you for this tutorial ;) realUrl is great

    thanks mate
  10. on Thursday, 03-07-08 00:55 Thorsten
    Dmitry, thank's for that very good tutorial. I have watched and listen your tutorials at the T3DD08. It was great, thank's!

    Greets
    Thorsten
  11. on Monday, 15-09-08 19:28 Teyhan Aktan
    hi Dimitry
    http://domain.de/folder/myvars/10/20/xyz.html
    i want just
    http://domain.de/folder/myvars/10-20-xyz.html
    is this possible with realurl?

Leave a Reply