Sans forcément refaire un article en repartant de zéro pour vous expliquer comment mettre en place realurl, je vous propose ici un exemple de fichier de configuration de realurl que vous pouvez mettre en place. Cette exemple se présente sous la forme du PHP à placer dans le fichier de configuration de realurl. Dans ce fichier, j’ai choisi de faire une configuration assez détaillée dans laquelle j’externalise chaque paramètre. Cette configuration gère entre autre le multidomaine, le multilinguisme, ainsi que tt_news. Cependant, en terme d’optimisation (si nécessaire), il est plus intéressant de sérialiser les choses (et du coup de perdre le côté dynamique de cette configuration).

Dans les premières lignes de ce fichier on retrouve en commentaire un bref récapitulatif des choses à faire pour mettre en place realurl (configuration apache et typoscript). Dans un deuxième temps, il est nécessaire de renseigner le « defaultRootPageId » qui détermine l’ID de la page d’accueil par défaut de votre site. Si votre site est multidomaine, il est nécessaire de remplir le tableau « domains » comme indiqué dans l’exemple du fichier.

<?php

	/***************************************************************
	*  Copyright notice
	*
	*  (c) 2009 Yohann CERDAN <cerdanyohann@yahoo.fr>
	*  All rights reserved
	*
	*  This script is part of the TYPO3 project. The TYPO3 project is
	*  free software; you can redistribute it and/or modify
	*  it under the terms of the GNU General Public License as published by
	*  the Free Software Foundation; either version 2 of the License, or
	*  (at your option) any later version.
	*
	*  The GNU General Public License can be found at
	*  http://www.gnu.org/copyleft/gpl.html.
	*
	*  This script is distributed in the hope that it will be useful,
	*  but WITHOUT ANY WARRANTY; without even the implied warranty of
	*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	*  GNU General Public License for more details.
	*
	*  This copyright notice MUST APPEAR in all copies of the script!
	***************************************************************

	//************************************** Configuration TS de realurl

	// Disable static document simulation
	config.simulateStaticDocuments = 0

	// Prefix anchors
	config.prefixLocalAnchors = all

	// baseURL
	config.baseURL = http://www.mysite.com/
	[hostname = www.mysite.com]
	config.baseURL = http://www.mysite.com/
	[global]

	// Enable RealURL
	config.tx_realurl_enable = 1

	//************************************** Nettoyage manuel des urls stockées si besoin (requêtes SQL)

	TRUNCATE `tx_realurl_chashcache`;
	TRUNCATE `tx_realurl_pathcache`;
	TRUNCATE `tx_realurl_uniqalias`;
	TRUNCATE `tx_realurl_urldecodecache`;
	TRUNCATE `tx_realurl_urlencodecache`;
	UPDATE `pages` SET `tx_realurl_pathsegment` = '';

	//************************************** .htaccess à la racine du site

	RewriteEngine On
	RewriteRule ^/typo3$ - [L]
	RewriteRule ^/typo3/.*$ - [L]
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_FILENAME} !-l
	RewriteRule .* /index.php

	//************************************** Multi-domaines

	- Créer l'enregistrement de type domaine dans l'arbo
	- Renseigner domains en indiquant le domaine et le root id

	**/

	//************************************** Configuration des domaines/pages

	// ID de la rootpage par defaut
	$defaultRootPageId = 6;

	// En cas de multi-domaines: liste des domaines => id de page root (voir exemple)
	$domains = array (
		// 'www.mysite.com' => 12,
		// 'www.mysite2.com' => 16,
	);

	//************************************** Configuration de la reecriture

	// Création de la config par défaut
	$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'] = array ('_DEFAULT'=>array());

	// Initialisation
	$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['init'] = array (
		'enableCHashCache' => true,
		'appendMissingSlash' => 'ifNotFile,redirect',
		'adminJumpToBackend' => true,
		'enableUrlDecodeCache' => true,
		'enableUrlEncodeCache' => true,
		'emptyUrlReturnValue' => '/',
		'useCHashCache' => 1,
		'postVarSet_failureMode' => 'redirect_goodUpperDir',
		'doNotRawUrlEncodeParameterNames' => 1,
		'enableCHashCache' => 1,
		'respectSimulateStaticURLs' => 1
	);

	// Redirections
	$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['redirects'] = array ();

	// Prevars
	$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['preVars'] = array (
		// No cache
		array(
			'GETvar' => 'no_cache',
			'valueMap' => array(
				'no_cache' => 1,
			),
			'noMatch' => 'bypass',
		),

		// Langue
		array(
			'GETvar' => 'L',
			'valueMap' => array(
				'fr' => '0',
				'en' => '1',
			),
			'noMatch' => 'bypass',
		)
	);

	// Méthode de transformation
	$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['pagePath'] = array (
		'type' => 'user',
		'rootpage_id' => $defaultRootPageId,
		'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
		'spaceCharacter' => '-',
		'languageGetVar' => 'L',
		'disablePathCache'    => 0,
		'expireDays' => 3,
		'segTitleFieldList'    => 'tx_realurl_pathsegment,alias,nav_title,title',
		'excludePageIds'    => null,
		'autoUpdatePathCache' => true
	);

	// Fixed post variables
	$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['fixedPostVars'] = array ();

	// Post variables
	$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['postVarSets'] = array (
		'_DEFAULT' => array(

			// Tt_news archives
			'archive' => array(
				array(
					'GETvar' => 'tx_ttnews[year]' ,
				),
				array(
					'GETvar' => 'tx_ttnews[month]' ,
					'valueMap' => array(
						'january' => '01',
						'february' => '02',
						'march' => '03',
						'april' => '04',
						'may' => '05',
						'june' => '06',
						'july' => '07',
						'august' => '08',
						'september' => '09',
						'october' => '10',
						'november' => '11',
						'december' => '12',
					)
				),
			),

			// Tt_news archives pagebrowser
			'newspage' => array(
				array(
					'GETvar' => 'tx_ttnews[pointer]',
				),
			),

			'newsyear' => array(
				array(
					'GETvar' => 'tx_ttnews[calendarYear]',
				),
			),

			// Tt_news categories
			'newscat' => array (
				array(
					'GETvar' => 'tx_ttnews[cat]',
				),
			),	 

			// tt_news articles
			'article' => 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' => '-',
						),
					),
				),
				array(
					'GETvar' => 'tx_ttnews[swords]',
				),
			),
		)
	);

	// FileName
	$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['_DEFAULT']['fileName'] = array (
		'defaultToHTMLsuffixOnPrev' => 0,
		'acceptHTMLsuffix' => 1
	);

	// Configuration des autres domaines
	if (count($domains)>0) {
		foreach ($domains as $domainKey=>$domainVal) {
			$TYPO3_CONF_VARS['EXTCONF']['realurl'][$domainKey] = $TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT'];
			$TYPO3_CONF_VARS['EXTCONF']['realurl'][$domainKey]['pagePath']['rootpage_id'] = $domainVal;
		}
	}

?>

Pour la copier, utilisez le bouton « copy to clipboard » et créez un fichier contenant le code PHP. Vous devrez ensuite renseigner dans le backend et dans le gestionnaire d’extension le chemin de ce fichier.

N’hésitez surtout pas à me faire des retours sur cette configuration afin de l’améliorer au fil du temps.

Partager :