Dynamic Sub Domains
Hi and Welcome
Apparently in 2007 blogs are going to peak, meaning after that they will decline. As a web designer I have decided I don’t want to miss out and have decided to build up a blogging empire! I have 4 main objectives in writing these blogs as listed below:
1. As another creative outlet and a means to share ideas with other people
2. To generate traffic to help boost all of the other sites I build
3. To possibly generate some revenue through google adsense and other advertising
As this is the first post, probably no one will be reading this except myself and possibly few search engines, but over the course of the next couple of months I am going to employ various techniques and strategies to boost the amount of traffic. I will be listing these techniques and ideas here in the hope that someone else will find them useful.
In this post I want to talk about something I only found out about the other day, dynamic sub domains. As you probably know, this site itself is hosted on a sub domain, http://blog.voodoochilli.com. The actual domain www.voodoochilli.com is my company website and the blog part is the sub domain. I know from experience that sub domains can rate very highly search engine wise, and they are a very cheap alternative to buying a fully qualified domain as there are no extra registration costs (although your hosting company may charge you a set up for a sub domain)
Dynamic sub domains means that you can generate these on the fly using a .htaccess file. First though you have to make sure you have wildcard dns turned on for your domain. You can test this by typing anything.yourdomainname.com and if you don’t get a 404 page the chances are this is already set up. Once you have this in place you need to look into .htaccess.
Heres an example of a .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\\.yourwebsite.com
RewriteCond %{HTTP_HOST} ([^.]+)\\.yourwebsite.com
RewriteRule ^(.*)$ /path_to_your_site/httpdocs/work_out.php?url=%1
Remember: This file must be called .htaccess exactly, with no file extension; when you upload it to your server it will probably be invisible so keep a backup!
The .htaccess file will then send the variable $url with the sub domain, so for example if you type in:
http://test.yourwebsite.com
This will translate to (but not be visible as)
http://www.yourwebsite.com/work_out.php?url=test
On one of my sites the work out page checks the MYSQL database for the username and simply brings up the profile for that person. As far as a visitor is concerned we are actually at http://test.yourwebsite.com. There are other ways of doing this, but after looking it up this seems the easiest.