
|
 |
Subdomains
Posted on: March 7, 2000, 3:20 a.m.
Home Free and subdomains, the real sotry
Recently we have gotten many people asking us if Home Free has the capability to allow their users subdomains, as in: username.domain.com.
The answer is no, but don't look so disappointed. Home Free can't, but Apache can. If your running the Apache webserver and the mod_rewite module is installed, giving subdomains to your users is as easy as adding 10 lines of new text to the Apache Configuration files. If you check the demo here on hf-online.com you will notice we have done this, and any base account can be accessed as username.hf-online.com or www.username.hf-online.com. These 10 lines work for every new user as well, nothing new needs to be added or hacked when a new member signs on. This setup will allow users in the base directory as well as categories to have subdomains, sub-categories will not work. Users in categories will have to use the url with the category in it. username.category.domain.com
Subdomain Setup
1. The first step is to make sure your dns for your domain can handle wildcards. If it can not then you either can not use subdomains, or must update your dns records to allow wildcards. To test your domain, try typing into an address bar of any browser wildcards.yourdoamin.tld (of course inserting your domain) If your front page of your website appears you can continue, wildcards are on, if you get a dns error or error of anykind, wildcards are not on and the dns for your domain must be changed.
2. Make sure mod_rewrite is install and on, some claim mod_rewite does not come installed by default, but from what I have seen it does for most.
3. Open your apache http.conf configuration file and add the following to the bottom:
Rewritelog logs/rewrite.log
RewritelogLevel 9
RewriteMap lowercase int:tolower
RewriteEngine on
RewriteCond ${lowercase:%{HTTP_HOST}} !^$
RewriteCond ${lowercase:%{HTTP_HOST}} !^www\.hf-online.com$
RewriteCond ${lowercase:%{HTTP_HOST}} ^(www\.|)([^.]+)\.hf-online\.com$
RewriteRule ^(.+) ${lowercase:%{HTTP_HOST}}$1 [C]
RewriteRule ^(www\.|)([^.]+)\.hf-online\.com(.*) /users/$2$3 [L]
RewriteCond ${lowercase:%{HTTP_HOST}} ^(www\.|)[^.]+\.[^.]+\.hf-online\.com$
RewriteRule ^(.+) ${lowercase:%{HTTP_HOST}}$1 [C]
RewriteRule ^(www\.|)([^.]+)\.([^.]+)\.hf-online\.com(.*) /users/$3/$2$4 [L] |
The first 2 lines:
Rewritelog logs/rewrite.log
RewritelogLevel 9 |
are used for debugging purposes, if something is not working right, like the subdomains are not forwarding correctly, look in the rewrite.log in your logs directory. It will help you figure out what is going wrong. These 2 lines should be commented out once everything is working ok. Comment by adding a # in front of them.
The next to lines, tell Apache we are going to use mod_rewrite and also set the lowercase function. (so the subdomains are case insensative)
The next 2 lines check and see if a subdomain exists (if one doesn't, no further mod_rewriting is done) and also makes sure the subdomain is not www
The next 6 lines are basically the same 3 lines written twice. The bottom 2 set of 3 lines is used for the category subdomains and can be removed if you do not use categories. This setup also allows your users to use www.username.domain.com and allow the www to be dropped and username.domain.com to also work.
You need to replace hf-online\.com with your domain name, keeping in mind to put a \ before the . You also need to replace the /users with the virtual directory to your base directory for Home Free users. Thus if your members currently access their sites at domain.com/members/username you would replace user with members
Rewritelog logs/rewrite.log
RewritelogLevel 9
RewriteMap lowercase int:tolower
RewriteEngine on
RewriteCond ${lowercase:%{HTTP_HOST}} !^$
RewriteCond ${lowercase:%{HTTP_HOST}} !^www\.hf-online.com$
RewriteCond ${lowercase:%{HTTP_HOST}} ^(www\.|)([^.]+)\.hf-online\.com$
RewriteRule ^(.+) ${lowercase:%{HTTP_HOST}}$1 [C]
RewriteRule ^(www\.|)([^.]+)\.hf-online\.com(.*) /users/$2$3 [L]
RewriteCond ${lowercase:%{HTTP_HOST}} ^(www\.|)[^.]+\.[^.]+\.hf-online\.com$
RewriteRule ^(.+) ${lowercase:%{HTTP_HOST}}$1 [C]
RewriteRule ^(www\.|)([^.]+)\.([^.]+)\.hf-online\.com(.*) /users/$3/$2$4 [L] |
4. Thats it. Upload your http.conf file, restart apache and test. If you do not get redirected to the proper place, check your rewrite.log dir. If everything is working fine, be sure to remove the 2 debugging lines. Now email your users and let them know of your new feature.
For more fun with mod_rewrite, check the Apache mod_rewrite users guide
|
|