Thursday, April 16, 2009

TYPO3: Enable realURL

By default typo3 uses URLs such as this: index.php?id=45. This is not very useful, it does not look good and is not "search engine friendly". Therefore it would be nice to havehttp://www.mysite.com/contact/instead of http://www.mysite.com/index.php?id=45In typo3, to do this you need to have RealURL extension installed. As I remember I had no problems installing it, or maybe it is installed by default, I'm not sure. Anyway, although installation of RealURL was easy, it was not so easy to make it work. I was creating some simple site using typo3, and I needed the most simple way to translate my address (e.g. from /index.php?id=45 to /contact/). The manual on the RealURL website is not so easy to understand, and it seems to be not updated (RealURL wiki seems to be better). For example in TypoScript configuration section the manual, it is said that we should set the following variable in TypoScript template recordconfig.baseURL = 1Unfortunately doing this results in an error: Unsupported TypoScript property was found in this template: "config.baseURL="1": The current version of typo3, at the moment of writing this, was 4.2.2!. So it seams this manual was not updated for a while. To solve this, in my case I needed to set this variable toconfig.baseURL = http://www.mysite.com/

Threfore, it took me a while to make this simple translation work. So what I did?

First, I made sure that mod_rewrite module was installed and working in my Apache (I had ubuntu-server 8.04 LTS and typo3 4.1.2). How exactly? There is plenty of information how to do this in the Internet, so I will not repeat it. Sorry:-).

Second, I enabled .htaccess in the root of your TYPO3-installation directory that comes with typo3 mv _.htaccess .htaccess

Third, I added config.simulateStaticDocuments = 0
config.baseURL = http://www.mysite.com/
config.tx_realurl_enable = 1
to in the TypoScript record. This record is in Template menu for root page of your site three, i.e. With this, if everything is ok, your realURL should already work! For me, it translated addresses from http://www.mysite.com/index.php?id=45tohttp://www.mysite.com/45

Forth, the manual says that file typo3conf/localconf.php should be edited for definition of translation rules. But for me it was enough to make aliases for each page to have e.g. "contact" instead of number 45:I did not have to edit localconf.php file. Thought, for more advanced translations probably you have to edit it.

Because I'm not sure whether I modified .htaccess I attach it here. localconf.php is also attached here.