TYPO3: Configuration of RealURL





by Bernd Warken at Netcos AG









Chapter 0: Introduction

0.1 Preface

0.2: License

Chapter 1: The RealURL Extension

1.1 Installation

1.2 Template Configuration

1.3 Configuration of the Web Server

Chapter 2: Adaption of typo3conf/localconf.php

2.1 Simple Domain

2.2 Several Domains

2.3 File Import instead of Annex

2.4 News and more







Chapter 0: Introduction



0.1 Preface

RealURL is an TYPO3 extension that generates speaking names for the page URLs created by TYPO3. With this document, you will be able to let replace cryptic default attributes, such as http://www.mysite.com/index.php?id=1&L=1 by names like http://www.mysite.com/de/home.

The idea for this project originates from the German training DVD

Einstieg in TYPO3 4.0

Von den Grundlagen bis zur professionellen Website

by Thomas Kötter

ISBN 3-89842-856-7

This DVD is very good and is recommended, it is suitable for beginners as well as for advanced usage of TYPO3. A data file of the DVD on the subject RealURL is available in the internet at

http://www.galileocomputing.de/download/dateien/1118/realurl.zip

This file can also be used by English speaking people with small changes. The default language and the foreign language must just be exchanged in the configuration files.

A further internet site that deals with the configuration of RealURL is

http://www.cross-content.com/typo3-tutorial/realurl-funktioniert.html

It is written in German, but the source code is independent of the language.

The source code of both sites can also be learned from the manual of the RealURL extension. It is found at typo3.org at DocumentationExtension Manuals RealURL (realurl).





0.2: License



This document belongs to the TYPO3 project RealURL. The actual version is 1.1 of 29 August 2007. The author is Bernd Warken at netcos AG.

The document is stored in the OpenOffice file format .sxw of version 1 and in the HTML format .html.

This document runs under the license GPL (GNU General Public License) version 3. The original text of this license is available at http://www.gnu.org/licenses/gpl.html.







Chapter 1: The RealURL Extension

1.1 Installation


RealURL is an extension of TYPO3. Before it can be used it needs to be downloaded first. This is done by the Ext Manager within the TYPO3 backend. There select the menu point Import extensions. Eventually some more extensions must be installed as well. If the installation guide is followed this is done automatically. Just take care that none of the arising windows is closed directly, but only by clicks on the suitable fields.



1.2 Template Configuration



In order that RealURL is able to work, it needs to be configured in the TypoScript template. For that, three command of the config area are necessary:

config {

simulateStaticDocuments = 0

baseURL = http://mysite.com

tx_realurl_enable = 1

}



The command config.simulateStaticDocuments = 0 deactivates a former version of RealURL, which only worked very limited. When activated a malfunction would arise.

The command config.baseURL makes not only sense in RealURL. It defines the URL of the website under which TYPO3 or the domain runs. It points to the directory containing the file index.php. For a local development environment the command could be

config.baseURL = http://localhost/typo3/entwicklung

as well.

For each domain, a suitable baseURL variable should be set on the propoer template pages.

The command config.tx_realurl_enable finally activates the usage of RealURL if its value is set to 1. The value 0 deactivates RealURL.



1.3 Configuration of the Web Server

Here we deal only with the web server Apache2. To use RealURL, the configuration of the Rewrite engine is necessary. For that, the Rewrite module must be installed.

Next the Rewrite engine must be configured for its TYPO3 installation. This requires that a file .htaccess must be configured in the root directory of the TYPO3 installation. With actual TYPO3 versions, there is already a file _.htaccess in this directory. This can just be renamed into .htaccess. This file is relatively large and contains already many preinstallations. By the good documentation within this file, it is easy to suit this file to the actual system.

The line

RewriteEngine On

Must be activated in any case.

If only one domain is used in the TYPO3 installation the command

RewriteBase /path

can be used, where /path is the path relative to http://my.domain or http://localhost. For example, the path to http://localhost/ is just /, but to http://localhost/typo3/mysite/ it is /typo3/mysite/.

If several domains are used in TYPO3 installation, it is recommended to add the following lines for each domain instead of RewriteBase into .htaccess:

RewriteCond %{HTTP_HOST} my.domain$ [NC]

RewriteRule ^$ /index.php?id=129

The id value, however, is not 129, but the real page id within the TYPO3 pages. For my.domain the real domain name must be inserted. An existing line with RewriteBase must then be commented out.

The following commands or similar elements might already be available in the file .htaccess.

RewriteRule ^(typo3|t3lib|tslib|fileadmin|typo3conf|typo3temp|uploads|showpic\.php)/ - [L]

RewriteRule ^typo3/.*$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* index.php [L]










Chapter 2: Adaption of typo3conf/localconf.php

The default configuration of RealURL is not very impressive. For optimal usage, the file typo3conf/localconf.php should be extended.

2.1 Simple Domain

We now explain an extension for the file typo3conf/localconf.php that is enough for the configuration of a TYPO3 project with a single domain. This extension is based on the default language English with the id L=0 and one foreign language German with the id L=1. The root page needs not be given, it is found automatically. The source code originates from

http://www.galileocomputing.de/download/dateien/1118/realurl.zip

and looks like

$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(

'_DEFAULT' => array(

'redirects' => array(),

'preVars' => array(

array(

'GETvar' => 'L',

'valueMap' => array(

'en' => '0',

'de' => '1',

),

'valueDescription' => array(

'en' => 'English',

'de' => 'Deutsch',

),

'noMatch' => 'bypass',

),

),

'pagePath' => array(

'type' => 'user',

'userFunc' =>

'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',

'spaceCharacter' => '_',

'languageGetVar' => 'L',

'expireDays' => 7,

),

'fixedPostVars' => array(),

'postVarSets' => array(),

),

);



This source code is appended near the end of the file, but before the final line

?>



Before you append it please test whether the file does not have already a RealURL configuration. This can be recognized by an exiting line

$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(





2.2 Several Domains

For each domain of the TYPO3 installation, the following lines must be appended behind the former single domain extension

$TYPO3_CONF_VARS['EXTCONF']['realurl']['my.domain'] =

$TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT'];

$TYPO3_CONF_VARS['EXTCONF']['realurl']['my.domain']['pagePath']['rootpage_id'] = 129;

Please remove the line break after the first equal sign and replace the number 129 by the id of the root page.

Again the insertion is done before the final line

?>

in the file typo3conf/localconf.php.

Remember to make the file .htaccess suitable for your several domains (see the previous chapter).



2.3 File Import instead of Annex

It is possible to store the annex to a file and import it. For that, we store the whole content of chapter 2.1 and 2.2 into the file typo3conf/realurlconf.php.

<?php
  content of chapter 2.1 and 2.2
?>



Then we insert a single line at the end of the file typo3conf/localconf.php (even after the final line):

<?php include(PATH_typo3conf.'realurlconf.php'); php?> 



RealURL should work now.



2.4 News and more

If you want to use speaking names with news and other features you could look at the training DVD Einstieg in TYPO3 4.0 of Thomas Kötter. In the data file of the DVD

http://www.galileocomputing.de/download/dateien/1118/realurl.zip

there is a file Beispielkonfiguration RealURL.txt. This describes the extension of typo3conf/localconf.php for news and more.