Wildcard DNS and personalized content

I'll spread the word about something I find appealing: Personal subdomain with personalized content. I'm using the following methods:

Apache
Add these lines to the configuration file, httpd.conf.

#

Options FollowSymLinks
AllowOverride All

#

The “AllowOverride All” makes it possible to use .htaccess files. This is an example of such a file:

#

ForceType application/x-httpd-php

#

This allows me to create a file called “rss” and still let it be treated as a PHP-file. This makes it possible to create nicer links, like user.vided.org/edit instead of user.vided.org/edit.php. I also use this method with the RSS-feed, user.vided.org/rss.

OK, even more fun is this. Make ALL subdomains point to your server. You have to setup DNS like this: *.vided.org. (A-record) IP-address. Read more about this with a simple google-search: wildcard DNS. Or read this.

You have to setup a virtual server in your Apache config again by editing the configuration file, httpd.conf. Add these lines (example):

#

DocumentRoot /where/your/www/data/is/located/subfolder/
ServerName subfolder.vided.org
ServerAlias *.vided.org
#The customlog is another story, but worth checking out.
#CustomLog /somewhere/log/httpd-users.vided.org.log combined

#

Now ALL subdomains point to a subfolder of your choice. Nice! This makes misspelled addresses like “ww.vided.org” get to your server. But it is still some way to go before this is _really_ fun. Let's make some PHP code…

// get server http request info (subdomain)
$serverhost = explode( '.' , $_SERVER["HTTP_HOST"]);

// Actually this is a "hack". It gets the first word/phrase before a "."
// This means that both anna.vided.org and anna.is.really.stupid.vided.org
// leads to the same content.

// get subdomain
$subdomain = $serverhost[0];

// get server http request info (example: getting info from "user.vided.org/archives/37")
$uri = explode( '/' , $_SERVER["REQUEST_URI"]);

//This gets the complete address like "archives/37"
$completeuri = $_SERVER["REQUEST_URI"];

// This should get "archives"
$function = $uri[1];

// This should get "37"
$archivenumber = $uri[2];

?>

OK, now we've got a script that can tell us what the user typed. This can be used in SQL-queries, which I do. I serve the vlog of the user “ag” when you type “ag.vided.org”. And whenever you type ag.vided.org/rss, you get the RSS-feed from ag.

Leave a Reply