Forum Moderators: phranque
I would like to ask, would it be possible to use Mod Rewrite, or a PHP script to dynamically create sub-domain,
when a new user register to say a forum or something? I'm using vB at present. If it helps, I'm using a shared server.
Thanks in advance.
Welcome to WebmasterWorld!
Yes it's possible, but there are many details that have to be taken care of. Here's a brief outline:
1) Make sure your host supports wild-card subdomains on your server.
2) Add an "A" record to your DNS zone file to define the wild-card subdomains.
3) Create a script that will validate new usernames (character-set must be limited to be sure that resulting URLs are valid).
4) The script should create a subdirectory to store the user's files.
5) Write some mod_rewrite code to rewrite (not redirect) subdomain requests to the users' subdirectories. (there are plenty of examples of that code here, do a search.)
I have not addressed issues like keeping users out of each other's directories, as the methods used would depend upon your specific requirements.
You will need a method to control how big each user's subdirectory can be; otherwise, you're likely to run into problems with your host if your site gets popular. Plan ahead.
Jim
For the record, server-side coding ain't my strongest strength but it's something I'm whiling to learn, try, digest and maybe understand. Guess a idiots guide to writing mod-rewrite and php script would be good, right about now. Guess I'm saying I'm a noob.
Well anyway, I just checked with my host, it seems "A" is clearly set in all my present sub-domains and "MX" is set for mail.
However, I'm curious is there a secure way of doing this, whereby non-admins (or users) can't see into other users ftp/web accounts. With the exception of the site admin.
OK.. How and were do I start?
Jeez.. don't even know what this is called. :s
There are also the WebmasterWorld server-side scripting forums -- PHP and PERL.
Each forum also has a section in the WebmasterWorld Library [webmasterworld.com] -- A collection of the more useful posts.
There is no motivator quite so good as a current need, and you've got one.
This project is both more difficult than it seems (in identifying the technical details of what must be done), and simpler than it seems (only 4 lines of code in .htaccess or httpd.conf, and maybe a couple of pages worth of script code) maximum.
And you're right, learning the technical terms for things is part of the challenge. I'd call this project, "adding support for user-created subdomains."
Jim
However, are there any commercial books you'd recommend for code Mod-rewrite and HTaccess, as a guide? I can't been to get my head around all the jargon plus, I'd like something I can read when not on the computer?
Currently, I find myself literally glued to this thing, even when I'm not working.
Cheers.
Laz