Realurl/testing
From TYPO3Wiki
<< Back to Extension manuals page
Other RealURL topic: testing | manual in the Wiki | a project to write a configuration editor for RealURL
By: Sylvain Viart 17:43, 30 Oct 2004 (CEST)
Contents |
[edit] Installing RealURL
Tips found on the english mailing list:
[http://typo3.org/documentation/mailing-lists/english-main-list-archive/thread/64209/?tx_maillisttofaq_pi1%5Bsword%5D=Daniel%20Breest%20wrote%3A&tx_maillisttofaq_pi1%5Banswered_only%5D=0&tx_maillisttofaq_pi1%5Bmode%5D=1 TYPO3 3.5.0 and RealURL extension]
don`t know, where to get a working module for 3.5.0. Can you forward the latest version for typo3 3.5.0 to me please or at least give me a hint where i can download this version? if you go to the extension manager and choose "import extensions from online repository", you have to select the name of the extension after you connected to the online repository. On the new page that appears you have the possibility to choose the version of the selected ext to install.
During the realURL installation process you might get an error: "Failed to execute SQL : SQL CREATE TABLE tx_realurl_pathcache (...)" RealURL tries to create 2 tables but just can not, probably something to do with MySQL being too new. So if installing realURL makes appear a lot of errors, check if tables tx_realurl_pathcache and tx_realurl_uniqalias exist. If not manualy create it removing the "DEFAULT '0'" statement from the columns that are also marked as auto_increment :
CREATE TABLE tx_realurl_pathcache ( cache_id int(11) NOT NULL auto_increment, page_id int(11) DEFAULT '0' NOT NULL, language_id int(11) DEFAULT '0' NOT NULL, rootpage_id int(11) DEFAULT '0' NOT NULL, mpvar tinytext NOT NULL, hash varchar(10) DEFAULT NOT NULL, pagepath text NOT NULL, expire int(11) DEFAULT '0' NOT NULL, PRIMARY KEY (cache_id), KEY hash (hash) ) TYPE=MyISAM; CREATE TABLE tx_realurl_uniqalias ( uid int(11) NOT NULL auto_increment, tstamp int(11) DEFAULT '0' NOT NULL, tablename varchar(30) DEFAULT NOT NULL, field_alias varchar(30) DEFAULT NOT NULL, field_id varchar(30) DEFAULT NOT NULL, value_alias tinytext NOT NULL, value_id int(11) DEFAULT '0' NOT NULL, PRIMARY KEY (uid), KEY tablename (tablename) ) TYPE=MyISAM;
[edit] Configuring RealURL
The documentation of RealURL is not so bad, but is far from user friendly. The first statement about the configuration is good enough to get started.
- Configure Apache and mod_rewrite
- Configure the extension
- in ext_localconf.php, in the extension dir
- or typo3conf/localconf.php
At mod_rewrite setup rules it might already cause problem.
Be carefull that Apache behaves differently if the rules are inside a VirtualHost configuration or at other place. Here is a sample of correct VirtualHost configuration.
File: httpd.conf
##
## httpd.conf -- Apache HTTP server configuration file
##
<VirtualHost 10.0.1.2>
ServerAdmin sylvain (at) ledragon.net
DocumentRoot /home/www/typo3/camping/
ServerName camping.ledragon.net
ErrorLog /home/www/typo3/log/camping_error.log
CustomLog /home/www/typo3/log/camping_access.log common
<Directory />
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride All
DirectoryIndex index.php index.html index.htm
# RealURL TYPO3 extension mod_rewrite configuration
RewriteEngine On
RewriteRule ^/typo3$ - [L]
RewriteRule ^/typo3/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* /index.php
</Directory>
# RewriteLog /home/www/typo3/log/rewrite.log
# RewriteLogLevel 0
UseCanonicalName On
</VirtualHost>
# vim: set ft=apache:
It does not work well if the rewrite rules are not inside <Directory>, because the VirtualHost location (path) is not correctly prepended by mod_rewrite. You can see it in debug mode RewriteLogLevel > 3, remove the old log file, and restart apache.
[edit] mod_rewrite rules
Here are the mod_rewrite rules proposed in the RealURL extension manual.
RewriteRule ^/typo3$ - [L]
RewriteRule ^/typo3/.*$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* /index.php
This group of rules says in human language:
- do not rewrite any URL which start with '/typo3' and serve it as usual, for the first 2 rules.
- If the URL is not requesting an existing directory (-d) or a file (-f) or a symlink -(l), then rewrite any url to /index.php. TYPO3 and realURL will do the rest.
Or better, you can change the last rule:
RewriteRule (\.html|/)$ index.php
In .htaccess (instead of httpd.conf) you'll have to use "index.php" without the leading slash!
There's also an example of .htaccess file in the root folder of any TYPO3 package: _.htaccess.
[edit] RealURL: config in localconf.php
What I have:
- my.domaine/index.php?id=12&L=1
- my.domaine/index.php?id=12
- my.domaine/index.php?id=12&L=4
What I want:
- my.domaine/en/the-nice-page-name.html
- my.domaine/en/the-nice-page-name/subpage-name.html
I don't want any folder link, only a page link. Only the site root can be served by http://my.domain/. After that the link should be http://my.domain/fr/accueil.html or http://my.domain/en/home.html.
[edit] Your time saver
- set the <base> tag correctly, in Template TSconfig (Setup).
- config.baseURL = 1
- this will not work from 3.8.1 on, you may check [globalString = ENV:HTTP_HOST=www.domain.tld] to set different baseURL for each HTTP_HOST
- config.baseURL = http://my.domaine/subfolder/
- which sould output the HTML <base href="http://my.domain/subfolder/"> in your page header.
- config.baseURL = 1
- clear DB cache
tx_realurl_pathcache is not cleared because it can hold old page name pointer, See tx_realurl_advanced.
[edit] BE show mode configuration
BE show mode, is when you want to see a page view from the BE, by selecting the Show function
.
Seems not currently supported...
[edit] Current RealURL config
My current config, almost work.
Everything seems to work except some glitch, but tend to be self removed by page caching.
Root page translation is not working.
I got : http://camp.ledragon.net/it.html I would like http://camp.ledragon.net/it/home.html
This config is a modified version of the one available on http://typo3.lehmano.de/realurl-config.html
I also set in ext/realurl/ext_localconf.php
//$TYPO3_CONF_VARS['FE']['addRootLineFields'].= ',tx_realurl_pathsegment'; $TYPO3_CONF_VARS['FE']['addRootLineFields'] .= ',tx_realurl_pathsegment,alias,nav_title,title';
typo3conf/localconf.php:
// RealURL configuration.
//
$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(
'camp.ledragon.net' => array(
'preVars' => array(
'0' => array(
'GETvar' => 'L',
'valueMap' => array(
'fr' => '0',
'en' => '1',
'it' => '4',
),
'valueDefault' => 'fr',
),
),
'fileName' => array(
'defaultToHTMLsuffixOnPrev' => '1',
),
'pagePath' => array(
'type' => 'user',
'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
'spaceCharacter' => '-',
'languageGetVar' => 'L',
'expireDays' => '3',
'rootpage_id' => '2',
),
'fixedPostVars' => array(
),
),
);
[edit] Entering RealURL PHP code
As my code for the language selector doesn't seem to work well with the RealURL extension, I decided to step into the extension code.
My problem is that my selector work properly without RealURL enabled. With RealURL a got URL like
http://camp.ledragon.net/index.php?id=2
instead of having
http://camp.ledragon.net/fr/acceuil.html
[edit] Why going into the Code ?
Reading the code seems currently the only available solution to debug RealURL.
[edit] Code logger
I've first seen some call to a logging function:
if (TYPO3_DLOG) t3lib_div::devLog('Entering encodeSpURL for '.$params['LD']['totalURL'], 'realurl');
This function, doesn't seem to produce any output. To view the logged output you need to install the extension CCDevlog (CCDevlog manual) .
See CCDevLog testing for more details about how to setup this extension.
[edit] RealURL processing step
[edit] Encoding URL
Going from TYPO3 native GET url to readable URL, when generating the page.
From
http://camp.ledragon.net/index.php?id=2
to
http://camp.ledragon.net/fr/acceuil.html
- Hook on linkData-PostProc in t3lib/class.t3lib_tstemplate.php:linkData()
- encodeSpURL() in ext/realurl/class.tx_realurl.php
- Call setConfig() to load the RealRUL configuration array regarding hotsname setting, this is the array defined in localconf.php, holded in $this->extConf.
- look for cached URL encodeSpURL_encodeCache()
- No ? encode a new URL encodeSpURL_doEncode()
- encodeSpURL_setSequence(), Traverses a set of GETvars configured (array of segments)
- encodeSpURL_pathFromId(), Creating the TYPO3 Page path into $pathParts from the "id" value in $param KeyValues
- No ? encode a new URL encodeSpURL_doEncode()
- encodeSpURL() in ext/realurl/class.tx_realurl.php
[edit] Example of localconf.php configuration
[edit] commented http://typo3.lehmano.de/realurl-config/
Unmodified but formated and with some comment. This example is for a site which could run tt_news extension.
// Activate script Hook, normaly already done in ext/realurl/ext_localconf.php
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tstemplate.php']['linkData-PostProc'][] =
'EXT:realurl/class.tx_realurl.php:&tx_realurl->encodeSpURL';
$TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['checkAlternativeIdMethods-PostProc'][] =
'EXT:realurl/class.tx_realurl.php:&tx_realurl->decodeSpURL';
// script Hook for clear all cache, normaly already done in ext/realurl/ext_localconf.php
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables']
['tx_realurl_urldecodecache'] = 'tx_realurl_urldecodecache';
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables']
['tx_realurl_urlencodecache'] = 'tx_realurl_urlencodecache';
$TYPO3_CONF_VARS['FE']['addRootLineFields'] .= ',tx_realurl_pathsegment,alias,nav_title,title';
// realurl config
$TYPO3_CONF_VARS['EXTCONF']['realurl'] = array(
'_DEFAULT' => array(),
//configuration matching only this domain
'typo3.lehmano.de' => array(
'init' => array(
'enableCHashCache' => 1,
// 'appendMissingSlash' => 'ifNotFile',
'enableUrlDecodeCache' => 1,
'enableUrlEncodeCache' => 1,
),
'redirects' => array(),
'preVars' => array(
//match &no_cache=1 with path prefix /nc
array(
'GETvar' => 'no_cache',
'valueMap' => array(
'nc' => 1,
),
'noMatch' => 'bypass',
),
//multiple language matching L=2 is replaced by /dk
//value are user defiened depending of the order you've inserted your
//alternative language in TYPO3. See sys_language table for ID
array(
'GETvar' => 'L',
'valueMap' => array(
'dk' => '2',
// 'dansk' => '2',
'de' => '1',
// 'deutsch' => '1',
),
'noMatch' => 'bypass',
),
),
// use extended page name rendering
// page names are converted to readalbe page/sub-page/sub-sub-page.html
'pagePath' => array(
'type' => 'user',
'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
'spaceCharacter' => '-',
'languageGetVar' => 'L',
'expireDays' => 7,
'rootpage_id' => 454,
// 'encodeTitle_userProc'=>'EXT:realurl/tx_realurl_encodeTitle_userProc.php:&user_encodeDates',
),
'fixedPostVars' => array(),
// match extension parameter
'postVarSets' => array(
'_DEFAULT' => array(
// archive
'period' => array(
array(
'condPrevValue' => -1,
'GETvar' => 'tx_ttnews[pS]' ,
// 'valueMap' => array(
//
// )
),
array(
'GETvar' => 'tx_ttnews[pL]' ,
// 'valueMap' => array(
//
// )
),
array(
'GETvar' => 'tx_ttnews[arc]' ,
'valueMap' => array(
'archived' => 1,
'non-archived' => -1,
)
),
),
// pagebrowser
'browse' => array(
array(
'GETvar' => 'tx_ttnews[pointer]',
),
),
'select' => array (
array(
'GETvar' => 'tx_ttnews[cat]',
'lookUpTable' => array(
'table' => 'tt_news_cat',
'id_field' => 'uid',
'alias_field' => 'title',
'addWhereClause' => ' AND NOT deleted',
'useUniqueCache' => 1,
'useUniqueCache_conf' => array(
'strtolower' => 1,
),
),
),
),
// backPid link
// 'back_to' => array(
// array('GETvar' => 'tx_ttnews[backPid]',
// 'lookUpTable' => array('table' => 'pages',
// 'id_field' => 'uid',
// 'alias_field' => 'title',
// 'addWhereClause' => ' AND NOT deleted',
// 'useUniqueCache' => 1,
// 'useUniqueCache_conf' => array('strtolower' => 1,
// 'spaceCharacter' => '-',
// ),
// ),
// ),
// ),
'article' => array(
array(
'GETvar' => 'tx_ttnews[backPid]',
),
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]'
),
),
),
),
// map some type to file name: rss.xml = &typo=100
'fileName' => array(
'index' => array(
'rss.xml' => array(
'keyValues' => array(
'type' => 100,
),
),
// 'index.html' => array(
// 'keyValues' => array(),
// ),
),
// add .html suffix to the end of the path generated
'defaultToHTMLsuffixOnPrev' => 1,
),
)
);
[edit] Modified language selector
Here is the script I use to produce the language selector. It seems to work with RealURL for now.
It's a modified version of the one used on the testsite. I didn't successfuly use the extension Language Selection (T3Ext:sr_language_menu) for my purpose. I need the default language to be French.
fileadmin/script/languageMenu.php
<?php
/***************************************************************
* Copyright notice
*
* (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com)
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
/**
* Creates a language-selector menu with three flags, an english, a danish and
* a german flag for each language supported on the site.
*
* THIS IS AN EXAMPLE designed to work with the official TYPO3 testsite,
* section "Another site in the ..." You will have to program a similar menu
* for your own case.
*
* $Id: example_languageMenu.php,v 1.5 2004/09/13 22:57:37 typo3 Exp $
* Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
* XHTML compliant
*
* @author Kasper Skaarhoj <kasperYYYY@typo3.com>
*/
class user_languageFlag {
function displayFlag($content,$conf) {
global $TYPO3_DB, $TSFE;
// First, select all pages_language_overlay records on the current page.
// Each represents a possibility for a language.
$res = $TYPO3_DB->exec_SELECTquery('*',
'pages_language_overlay',
'pid='.intval($TSFE->id).
$TSFE->sys_page->enableFields('pages_language_overlay'),
'sys_language_uid');
$langArr = array();
while($row = $TYPO3_DB->sql_fetch_assoc($res)) {
$langArr[$row['sys_language_uid']] = $row['title'];
}
// Little red arrow, which is inserted to the left of the flag-icon if
// the TSFE->sys_language_uid equals the language uid
// (notice that 0=french 1=english is SPECIFIC to this database,
// because these numbers refer to uid's of the table sys_language)
$pointer = '<img src="t3lib/gfx/content_client.gif" '.
'width="7" height="10" align="middle" alt="" />';
// language definition array
$languages = array(
'French' => array( 'uid' => 0, 'flag' => 'fr'),
'English' => array( 'uid' => 1, 'flag' => 'en'),
'Italian' => array( 'uid' => 4, 'flag' => 'it'),
);
$flag_pic = 'typo3conf/ext/sr_language_menu/flags/';
// Set each Flag icon. If the language is the current, red arrow is
// printed to the left. If the language is NOT found (represented by a
// pages_language_overlay record on this page), the icon is dimmed.
$flags = array();
// Create a Template object from t3lib/class.t3lib_tstemplate.php
$localTempl = new t3lib_TStemplate;
// Loop over each supported languages
foreach($languages as $lang => $def) {
// set the pointer if we are in current language
$HTML = $TSFE->sys_language_uid==$def['uid']?$pointer:'';
// flag picture, may be dimmed, if language support doesn't exist for
// the page.
$icon = '<img src="'.$flag_pic.
$def['flag'].($langArr[$def['uid']]||$def['uid']==0?'':'_d').
'.gif" '. 'width="21" height="13" hspace="5" border="0" alt="'.
$lang.'" title="'.$lang.'" />';
// related page link
// Better links with realURL extension supported by Template object
// linkData($page,
// $oTarget,
// $no_cache,
// $script,
// $overrideArray='',
// $addParams='',
// $typeOverride='')
$LD = $localTempl->linkData($GLOBALS['TSFE']->page,
'', // $oTarget
'', // $no_cache
'', // $script
'', // $overrideArray
'&L='.$def['uid'], // $addParams, need the & prefix to work
'0');
$link = $LD['totalURL'];
//$link = htmlspecialchars('index.php?id='.$TSFE->id.'&L='.$def['uid']);
$HTML .= '<a href="'.$link.'" target="_top">'.$icon.'</a>';
$flags[] = $HTML;
}
// Make the little menu. Notice, the menu does ONLY transfer the page-id
// and the "L" variable (which is also SPECIFIC for this website because
// "L" has been used in the extension template used to control the
// language setup)
return '<table border="0" cellpadding="0" cellspacing="0">'.
'<tr><td><img src="clear.gif" width="30" height="1" alt="" /></td>'.
'<td>'.implode('',$flags).'</td></tr></table>';
}
}
?>
[edit] Other RealURL examples
Put your own working example in the following page:

