View Full Version : User Subdomains (Wildcarded DNS)
housetohome
12-05-2005, 06:23 AM
Hi :)
Similar request to the URL redirection question in this thread: http://www.phpfox.com/members/viewtopic.php?t=142
Is it possible to have user subdomains? ie username.blogs.org pointing to the user's profile at www.blogs.org/user/?P=username
Turning on wildcarded DNS is relatively simple, but is there a quick way to set up forwarding?
I do something similar with my www.alias.org site, which offers short URL's.
Thanks!
Chris.
DeviouS
12-05-2005, 10:58 AM
You could try something like this in the .htaccess file.
Still can follow what was said on the other post, but just change the .htaccess file to this.
Content visible to registered users only.
If you have access to create wildcarded DNS then something like this should work.
You could also try:
http://forums.digitalpoint.com/showthread.php?t=33868
housetohome
12-05-2005, 11:06 AM
Thanks Devious :)
I think I figured out a very simple way that doesn't require any of the changes from the other thread. Once Wildcarded DNS is configured in the zone file, and the appropriate changes made to the httpd.conf <VirtualHost>, I simply added these few lines at the top of the index.php in the root (nothing else should be required at all):
$domain = $_SERVER['HTTP_HOST'];
$domain = str_replace("www.", "", $domain);
$parts = explode(".", $domain);
// note that this if statement needs to contain your second level domain name (eg blogs) if someone tries http://blogs.org
if ($parts[0] != "" and $parts[0] != "blogs")
header("Location: http://www.blogs.org/user/?P=" . $parts[0]);
Works like a charm from what I can tell so far.. (use at your own risk though!) :D It will work for http://chris.blogs.org or http://www.chris.blogs.org
Hopefully users are smarter than that though..
There's a wildcard DNS tutorial here, if anyone is interested:
http://photomatt.net/2003/10/10/wildcard-dns-and-sub-domains/
housetohome
12-06-2005, 02:29 AM
Thinking more about it, it would be possible to do something similar for folders, as in the other thread by placing a small amount of code in the root index.php. For example:
user goes to http://www.blogs.org/someusername
1) get $_SERVER(REQUEST_URI) (should be "/someusername")
2) does this path exist on the file system already? (easy to check with file_exists();
2a) if no - check database to see if user exists and then set header("Location: http://www.blogs.org/user/?P=someusername");
2b) if yes - ignore and break
Something to think about..
vBulletin® v3.6.10, Copyright ©2000-2009, Jelsoft Enterprises Ltd.