TYPO3: Configurable <base href="..."/> URL

When using RealURL in TYPO3, I prefer to set a <base href="http://example.org/"/> in the page since that makes generating links and linking CSS and JavaScript files much easier - and many extensions do not care about adding a / prefix to their links.

The TypoScript setup is easy:

config.baseURL = http://example.org/

Problem with this solution is that it works for a single host only and fails badly when having different systems - the developer machine and the live server. Now you have to remember setting up the URL on all systems correctly and do that on every change.

A better solution is to set the base URL automatically, depending on the current host header.

TypoScript constants:

BASEURL = http://example.org/
[globalString = ENV:HTTP_HOST=dev.example.org] 
  BASEURL = http://dev.example.org/
[globalString = ENV:HTTP_HOST=dev.example.org] AND [globalString =_SERVER|HTTPS=on]
  BASEURL = https://dev.example.org/

TypoScript setup:

config.baseURL = {$BASEURL}

Written by Christian Weiske.

Comments? Please send an e-mail.