directory support for Dot TK domain forwarding
A number of people that use Dot TK’s free domain forwarding miss the support for directories. They would like a hit on http://example.tk/subdir/ to go to http://example.com/whateverusername/examplepage/subdir/.
There is actually a pretty simple way to do this yourself. If your webserver supports scripting (like PHP in this example), you are basically done.
Lets say your webpage is hosted at http://domain.com/itsme/. You have registered itsme.tk at Dot TK and configured it to point to your webpage.
Now, you wish to have support for subdirectory /cheese/. In the example you would like http://itsme.tk/cheese/ to load content from http://domain.com/itsme/cheese/.
This is what you would need to do:
1. Rename the index.html page in the root directory of your website to index.php.
2. Insert the following code in top of that index.php:
<?php
// get the referer url
$ref = $_SERVER['HTTP_REFERER'];
// get the index of the 3rd /
$pos = strpos($ref, "/", 8) + 1;
if ($pos > 0) {
// if found, get whatever there was after the /
$path = substr($ref, $pos);
if ($path != '') {
// redirect browser to whatever current url + given path.
$url = $_SERVER['REQUEST_URI'] . $path;
header("Location: " . $url);
}
}
?>
3. Save the file.
4. You are done!
Not only will http://itsme.tk/cheese/ resolve to http://domain.com/itsme/cheese/, other requests like http://itsme.tk/index2.html would actually load the content of http://domain.com/itsme/index2.html.
What the above lines of PHP code do is the following. First, it reads the HTTP_REFERER variable from the webservers environment. This value holds the value of the URL entered by the website visitor. Secondly, it checks if this request has some text behind the / just right after the domain. If it does, it will forward the visitors browser to the requested page.
A note: Your webserver needs to be configured to allow php files as index files. How to do that is outside of the scope of this document, but should not be too hard.