Skip to content

Instantly share code, notes, and snippets.

@SchumacherFM
Created July 24, 2012 19:28
Show Gist options
  • Save SchumacherFM/3172086 to your computer and use it in GitHub Desktop.
Save SchumacherFM/3172086 to your computer and use it in GitHub Desktop.
Multidomain with RealURL #TYPO3
<?php
/*
assuming the following folder structure:
typo3conf/
|
L ext/
L domainconfig/
|
L domain-global.inc.php
L domain-de.inc.php
L domain-[country].inc.php
L different-a.inc.php
L different-b.inc.php
L localconf.php
L realurl_conf.php
L temp_*
a domainconfig include file will look like:
php-start-tag
$TYPO3_CONF_VARS['EXTCONF']['realurl']['domain-a.dev'] = $TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT'];
$TYPO3_CONF_VARS['EXTCONF']['realurl']['domain-a.dev']['pagePath']['rootpage_id'] = 248;
$TYPO3_CONF_VARS['EXTCONF']['realurl']['domain-a.dev']['pagePath']['errorpage_id'] = 1309;
$TYPO3_CONF_VARS['EXTCONF']['realurl']['www.domain-a.com'] = $TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT'];
$TYPO3_CONF_VARS['EXTCONF']['realurl']['www.domain-a.com']['pagePath']['rootpage_id'] = 248;
$TYPO3_CONF_VARS['EXTCONF']['realurl']['www.domain-a.com']['pagePath']['errorpage_id'] = 1309;
$TYPO3_CONF_VARS['EXTCONF']['realurl']['domain-a.com'] = $TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT'];
$TYPO3_CONF_VARS['EXTCONF']['realurl']['domain-a.com']['pagePath']['rootpage_id'] = 248;
$TYPO3_CONF_VARS['EXTCONF']['realurl']['domain-a.com']['pagePath']['errorpage_id'] = 1309;
php-end-tag
*/
// this is the main content of the realurl_conf.php
// a lot of common config values had been removed
// there is plenty of room for optimization
$TYPO3_CONF_VARS['FE']['addRootLineFields'].= ',tx_realurl_pathsegment';
$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(
'_DEFAULT' => array(
'init' => array(
'enableCHashCache' => 1,
'appendMissingSlash' => 'ifNotFile',
'enableUrlDecodeCache' => 1,
'enableUrlEncodeCache' => 1,
'enableUrlEncodeHash' => 1,
'postVarSet_failureMode' => '',
),
'redirects' => array(),
'preVars' => array(
array(
'GETvar' => 'no_cache',
'valueMap' => array(
'nc' => 1,
),
'noMatch' => 'bypass',
),
array(
'GETvar' => 'L',
'valueMap' => array(
'de' => '0',
'fr' => '1',
'en' => '2',
'it' => '3'
),
'valueDefault' => 'de',
'noMatch' => 'bypass',
),
),
'pagePath' => array(
'type' => 'user',
'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
'spaceCharacter' => '-',
'languageGetVar' => 'L',
'expireDays' => 7,
'rootpage_id' => 248,
'firstHitPathCache' => 1,
),
'fixedPostVars' => array(),
'postVarSets' => array(
'_DEFAULT' => array(
// removed a lof config ...
),
),
),
// configure filenames for different pagetypes
'fileName' => array(
'defaultToHTMLsuffixOnPrev' => 1,
'index' => array(
'print.html' => array(
'keyValues' => array(
'type' => 98,
),
),
),
),
),
);
// MULTI-DOMAIN HANDLING
// enter new domains here
$domainCfg = array(
'global' => array('dev-a.local','domain-a.com','www.domain-a.com'),
'domain-ch' => array('dev-ch.local','ch.domain.com'),
'domain-de' => array('dev-de.local','de.local.com'),
'domain-it' => array('dev-it.local','it.local.com'),
'different-a' => array('different-a.ch','www.different-a.ch','different-a.local'),
'different-b' => array('different-b.ch','www.different-b.ch','different-b.local' ),
);
$includeKey = '';
foreach ($domainCfg as $key => $domain) {
if (in_array($_SERVER['HTTP_HOST'], $domain)) {
$includeKey = $key;
break;
}
}
if ( $includeKey != '' ) {
// include the specific config-file
$file = 'typo3conf/domainconfig/'.$includeKey.'.inc.php';
require_once ($file);
}
/*
* -------------------------------------------------------------
* MULTI-LANGUAL ERROR PAGE HANDLING
* -------------------------------------------------------------
* # 'de' => '0', 'fr' => '1', 'en' => '2', 'it' => '3',
* -------------------------------------------------------------
*/
$tmpL = false;
$langshort = substr($_SERVER['REQUEST_URI'], 0, 4);
switch ($langshort) {
case '/fr/':
$tmpL = 1;
break;
case '/en/':
$tmpL = 2;
break;
case '/it/':
$tmpL = 3;
break;
default:
$tmpL = 0;
}
$TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = 'http://'.$_SERVER['HTTP_HOST'].'/index.php?id='.$TYPO3_CONF_VARS['EXTCONF']['realurl'][$_SERVER['HTTP_HOST']]['pagePath']['errorpage_id'].( $tmpL ? '&L='.$tmpL : '' );
$TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'] = 'HTTP/1.1 404 Not Found';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment