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.
Good tip, a way of using mod_rewrite i didn’t know!
Very nice!
Could you give me an example of how to mod_rewrite this one?
http://test.somedomain.com/category=1&page=1
I have no clue how to catch the parameters on the end (gallery, page)
Thanks!
[...] subdomains using htaccess I found this blog  about how to create dynamic subdomain using htaccess. I will try this at home later. Actually you [...]
going to revamp my site and am interested in how your workout.php sorted from the db and displayed content and kept the address to display test.yourdomain.com
hi
i need to do thie plz
i have this url
http://mysite.com/index.php?go=news
i need this url in this photo
news.mysite.com
by htaccess plz tell me answer
Janos
you would use php to capture the $_REQUEST variable and do with it whatever you want.For example
http://test.somedomain.com/category=1&page=1
Supposing the page is index.php on it just use:
$category;
and
$page;
Hi,
Firstly - thanks for publishing your work! I really want to use this for my site but don´t understand a few things.. perhaps you could clarify?
1) with the line of code: RewriteRule ^(.*)$ /path_to_your_site/httpdocs/work_out.php?url=%1 … I don´t understand the “path_to_your_site” part, path from where?? is this just my domain? Or are we digging back, like var/vhosts/mydomain.com?
2) Assuming I´ve got a dedicated server, with multiple virtual domains, where is the best place to put the .htaccess file? In the root directory of domain in which I want to use it? In the http_docs folder?
3) With the “workout.php” file… I guess that just processes the variable and re-directs as required, so in your example, with “url=test”, you would assume there is a normal sub-directory named “test” and the php script just redirects the user to that sub-directory? Correct? Or no?
Hope you can help…
Thanks!
Hi,
I tried this trick with my website, trying to redirect each wordpress category to a subdomain. It doesn’t work….
@Matthew: - it works fine for me
Works for me too!
i find to your try at
http://aksesmedia.co.cc/view/How-To-Create-Virtual-Subdomain-with-htaccess.html
regards
Not working for me !!!
c5j14B ega7Kl0dnDduqp6s2bnp1o