Requires the following to be added to settings.php (example below uses /beta).

if(isset($GLOBALS['request'])) {
  $scriptName = $GLOBALS['request']->server->get('SCRIPT_NAME');
  $scriptName = preg_match('#^/beta/#', $scriptName) ? $scriptName : "/beta$scriptName";
  $GLOBALS['request']->server->set('SCRIPT_NAME', $scriptName);
}