No, I'm sorry but after all my attempts to make this work with a routing php file, I see that it does mess up everything related to paths
In hiawatha.conf
UrlToolkit {
ToolkitID = wildcard
Match /(.*) Rewrite /route.php?$1
RequestURI exists Return
}
VirtualHost {
Hostname = *.example.com #replaced real hostname
WebsiteRoot = C:\wwwroot\www
StartFile = index.php
AccessLogfile = C:\Program Files\Hiawatha10\log\access.log #none
ErrorLogfile = C:\Program Files\Hiawatha10\log\error.log
ExecuteCGI = yes
UseToolkit = wildcard
SetEnv PHPRC = C:\phpinifiles\php.ini
TLScertFile = /config/certs/hiawatha.pem
RequireTLS = no
}
In route.php
<?php
$request_uri = explode("?", $_SERVER['REQUEST_URI'], 2);
$requested_subdomain = explode(".", $_SERVER['HTTP_HOST']);
$pathToFile = $requested_subdomain[0] . "/" . $request_uri[0];
$defaultPage = "index.php";
switch ($request_uri[0]) {
case '/': // Default page
require $requested_subdomain[0] . '/'. $defaultPage;
break;
case '/dumb': //Just an example, custom rewrites can be added this way
require 'dumb.php';
break;
default: // All regular requests
$pathToFile = str_replace("/route.php", "/", $pathToFile ); //don't allow people to ask for THIS file "route.php"
if( substr($pathToFile, -1) == "/" ) $pathToFile = $pathToFile . $defaultPage; //if request ends with "/", we add $defaultpage
if( !file_exists ( $pathToFile ) ){ //show that nasty custom 404 page if file doesnt exist
header('HTTP/1.0 404 Not Found');
require 'my404.html';
break;
} else {
$the_content_type = get_mime_type($pathToFile); //determine what mime type to tell browser we're sending it
header('Content-Type: ' . $the_content_type); //ensure that file types like pics show as they should
require $pathToFile;
break;
}
}
function get_mime_type($filename) { //quick and dirty, function that determines from a list of file extensions
$idx = explode( '.', $filename );
$count_explode = count($idx);
$idx = strtolower($idx[$count_explode-1]);
$mimet = array(
'txt' => 'text/plain',
'htm' => 'text/html',
'html' => 'text/html',
'php' => 'text/html',
'css' => 'text/css',
'js' => 'application/javascript',
'json' => 'application/json',
'xml' => 'application/xml',
'swf' => 'application/x-shockwave-flash',
'flv' => 'video/x-flv',
// images
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'ico' => 'image/vnd.microsoft.icon',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
// archives
'zip' => 'application/zip',
'rar' => 'application/x-rar-compressed',
'exe' => 'application/x-msdownload',
'msi' => 'application/x-msdownload',
'cab' => 'application/vnd.ms-cab-compressed',
// audio/video
'mp3' => 'audio/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
// adobe
'pdf' => 'application/pdf',
'psd' => 'image/vnd.adobe.photoshop',
'ai' => 'application/postscript',
'eps' => 'application/postscript',
'ps' => 'application/postscript',
// ms office
'doc' => 'application/msword',
'rtf' => 'application/rtf',
'xls' => 'application/vnd.ms-excel',
'ppt' => 'application/vnd.ms-powerpoint',
'docx' => 'application/msword',
'xlsx' => 'application/vnd.ms-excel',
'pptx' => 'application/vnd.ms-powerpoint',
// open office
'odt' => 'application/vnd.oasis.opendocument.text',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
);
if (isset( $mimet[$idx] )) {
return $mimet[$idx];
} else {
return 'application/octet-stream';
}
}
?>
This is as far as I got, and maybe somebody sees a bug in there or has improvements or would like to use the code for something, then go ahead, I'm really sad and disappointed that hiawatha can't do this particular thing as good as I hoped.
The setup that I made will work with less complicated webpages, like if you build up something on a subdomain from scratch and can adjust all paths etc in the php yourself, but I tried for instance to install a php webmail software and a forum software, in both cases it failed. From all my bughunting the only thing I can see is that it will mess up the paths etc.
So in my opinion it is not a solution to offer others, when they can't install basic softwares like forums etc.