--- /dev/null
+#!/bin/sh
+
+export LANGUAGE_DEFAULT="${LANGUAGE_DEFAULT:-en}"
+export HTTP_REFERER="${HTTP_REFERER:-$(HEADER Referer)}"
+
+case ${HTTP_REFERER} in
+ */:*/*):;;
+ */:*)
+ LANGUAGE_REFERRED="${HTTP_REFERER##*/:}"
+ ;;
+esac
+
+export LANGUAGE="${LANGUAGE_REFERRED:-${LANGUAGE_DEFAULT}}"
+
+case ${PATH_INFO} in
+ */:?*/\[attachment\]/?*)
+ export LANGUAGE="${PATH_INFO#*/:}"
+ LANGUAGE="${LANGUAGE%%/*}"
+ PATH_INFO="${PATH_INFO%%:?*/*}${PATH_INFO#*/:?*/}"
+ ;;
+ */:?*/\[attachment\])
+ export LANGUAGE="${PATH_INFO#*/:}"
+ LANGUAGE="${LANGUAGE%%/*}"
+ PATH_INFO="${PATH_INFO%:?*/\[attachment\]}[attachment]"
+ ;;
+ */:*/?*) # Never occurs
+ :;;
+ */:?*/) # Faulty URL build
+ REDIRECT "${_BASE}${PATH_INFO%/}"
+ ;;
+# */:"${LANGUAGE_DEFAULT}")
+# REDIRECT "${_BASE}${PATH_INFO%:*}"
+# ;;
+ */:?*)
+ export LANGUAGE="${PATH_INFO##*/:}"
+ if mdfile "${PATH_INFO}/"; then
+ PATH_INFO="${PATH_INFO}/"
+ elif [ "$LANGUAGE" = "$LANGUAGE_DEFAULT" ]; then
+ PATH_INFO="${PATH_INFO%:*}"
+ else
+ export ERROR_MSG="TRANSLATION NOT FOUND"
+ PATH_INFO="${PATH_INFO%:*}"
+ fi
+ ;;
+ /|*/*/)
+ if [ "$LANGUAGE_REFERRED" -a "$LANGUAGE_REFERRED" != "$LANGUAGE_DEFAULT" ]; then
+ REDIRECT "${_BASE}${PATH_INFO}:${LANGUAGE_REFERRED}"
+ fi
+ ;;
+ */:*/\[*\]) # Considered valid in most cases
+ :;;
+ */\[*\])
+ if [ "$LANGUAGE_REFERRED" -a "$LANGUAGE_REFERRED" != "$LANGUAGE_DEFAULT" ]; then
+ REDIRECT "${_BASE}${PATH_INFO%\[*\]}:${LANGUAGE_REFERRED}/[${PATH_INFO##*/\[}"
+ fi
+ ;;
+esac
+
+return 1