Site Navigation
Photo by John Carlisle on Unsplash of the colorful wires used to configure an analog synth

How I fixed my broken realURL configuration

From the Beginning

I been using TYPO3 and realURL for a long time now and I'm no expert but I've got my go-to setups and configurations that I use for the site I develop. At one time the author of realURl Dmitry Dulepov had published a best-practices article on how to configure realURL and that's what I've been using for a few years now. Here's what it looks like.

 

//Configure RealURL
$tx_realurl_config = array(
    'init' => array(
			'appendMissingSlash' => 'ifNotFile',
			'emptyUrlReturnValue'=>'/',
		),
		'redirects' => array(),
		'preVars' => array(
			'0' => array(
				'GETvar' => 'no_cache',
				'valueMap' => array(
					'nc' => 1,
				),
				'noMatch' => 'bypass',
			),
			'1' => array(
				'GETvar' => 'L',
				'valueMap' => array(
					'dk' => '2',
					'de' => '1',
				),
				'noMatch' => 'bypass',
			),
		),
		'fixedPostVars' => array(
			'newsDetailConfiguration' => array(
                        array(
                                'GETvar' => 'tx_news_pi1[action]',
                                'valueMap' => array(
                                        'detail' => '',
                                ),
                                'noMatch' => 'bypass'
                        ),
                        array(
                                'GETvar' => 'tx_news_pi1[controller]',
                                'valueMap' => array(
                                        'News' => '',
                                ),
                                'noMatch' => 'bypass'
                        ),
                        array(
                                'GETvar' => 'tx_news_pi1[news]',
                                'lookUpTable' => array(
                                        'table' => 'tx_news_domain_model_news',
                                        'id_field' => 'uid',
                                        'alias_field' => 'IF(path_segment!="",path_segment,title)',
                                        'addWhereClause' => ' AND NOT deleted',
                                        'useUniqueCache' => 1,
                                        'useUniqueCache_conf' => array(
                                                'strtolower' => 1,
                                                'spaceCharacter' => '-'
                                        ),
                                        'languageGetVar' => 'L',
                                        'languageExceptionUids' => '',
                                        'languageField' => 'sys_language_uid',
                                        'transOrigPointerField' => 'l10n_parent',
                                        'expireDays' => 180,
                                )
                        )
                ),
                'newsCategoryConfiguration' => array(
					array(
						'GETvar' => 'tx_news_pi1[overwriteDemand][categories]',
						'lookUpTable' => array(
							'table' => 'sys_category',
							'id_field' => 'uid',
							'alias_field' => 'title',
							'addWhereClause' => ' AND NOT deleted',
							'useUniqueCache' => 1,
							'useUniqueCache_conf' => array(
								'strtolower' => 1,
								'spaceCharacter' => '-'
							)
						)
					)
                ),
                'newsTagConfiguration' => array(
                        array(
                                'GETvar' => 'tx_news_pi1[overwriteDemand][tags]',
                                'lookUpTable' => array(
                                        'table' => 'tx_news_domain_model_tag',
                                        'id_field' => 'uid',
                                        'alias_field' => 'title',
                                        'addWhereClause' => ' AND NOT deleted',
                                        'useUniqueCache' => 1,
                                        'useUniqueCache_conf' => array(
                                                'strtolower' => 1,
                                                'spaceCharacter' => '-'
                                        )
                                )
                        )
                ),
				'10' => 'newsDetailConfiguration',
				'9' => 'newsDetailConfiguration',
                '3' => 'newsTagConfiguration',
                '3' => 'newsCategoryConfiguration',
				'9' => 'newsCategoryConfiguration',
		),
		'pagePath' => array(
			'spaceCharacter' => '_',
			'expireDays' => 7,
		),
		'postVarSets' => array(
			'_DEFAULT' => array(
   			// EXT:news start
			'news' => array(
									
					array(
						'GETvar' => 'tx_news_pi1[news]',
						'lookUpTable' => array(
								'table' => 'tx_news_domain_model_news',
								'id_field' => 'uid',
								'alias_field' => 'title',
								'addWhereClause' => ' AND NOT deleted',
								'useUniqueCache' => 1,
								'useUniqueCache_conf' => array(
										'strtolower' => 1,
										'spaceCharacter' => '-',
								),
								'languageGetVar' => 'L',
								'languageExceptionUids' => '',
								'languageField' => 'sys_language_uid',
								'transOrigPointerField' => 'l10n_parent',
								'expireDays' => 180,
						),
					),
			),
			// EXT:news end
   			//---------------------------------
			),
		),
		// configure filenames for different pagetypes
		'fileName' => array(
			'index' => array(
				'rss.xml' => array(
					'keyValues' => array(
						'type' => 100,
					),
				),
				'rss091.xml' => array(
					'keyValues' => array(
						'type' => 101,
					),
				),
				'rdf.xml' => array(
					'keyValues' => array(
						'type' => 102,
					),
				),
				'atom.xml' => array(
					'keyValues' => array(
						'type' => 103,
					),
				),
				'_DEFAULT' => array(
					'keyValues' => array(
					)
				),
			),
		),
);
/*
This is where you assign the realURL config array to the configured domains.

Remove any that don't apply
*/
$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(
  'www.domain1.com' => $tx_realurl_config,
  'www.domain2.com' => $tx_realurl_config,
);

/*
* Set the root page ID for each domain in typo3
*/

$TYPO3_CONF_VARS['EXTCONF']['realurl']['domain1.com']['pagePath']['rootpage_id'] = 1;
$TYPO3_CONF_VARS['EXTCONF']['realurl']['domain2.com']['pagePath']['rootpage_id'] = 7;


unset($tx_realurl_config);

 

What's Happening

I was updating my site with the latest TYPO3 version 7.6 and updating my extension at the same time and my menus and links broke. The main site navigation links all referaenced the site root and the news articles links didn't look at all like what I expected based on my realURL configuration.

For the real TYPO3 geeks out there they will probably see the error right away. It took me some time and searching to find the error of my ways. In fact there were two issues I needed to deal with to get my desired results. The first is that I wasn't setting TYPO3_CONF_VARS as I expected. The second was that the news extension realURL auto configuration was overriding my own configuration.

The Solution

 First I had to update the way I set the values in the TYPO3_CONF_VARS array. You can see the changes below. 

 

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

 

  'www.domain1.com' => $tx_realurl_config,
  'www.domain2.com' => $tx_realurl_config,
);

/*
* Set the root page ID for each domain in typo3
*/

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['domain1.com']['pagePath']['rootpage_id'] = 1;
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['domain2.com']['pagePath']['rootpage_id'] = 7;

 

Second, I had to unset the news extensions realURL auto configuration. To do this you will need an install extension. In my case I was able to add this line to the ext_localconf.php file of my template extension. 

added to my extension ext_localconf.php

 

//remove the new realurl auto config

 

 

unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/realurl/class.tx_realurl_autoconfgen.php']['extensionConfiguration']['news']);