*.domain.com tutorial
ok I have seen people bitching about this for a while and I figured that I would mess around with my server until I finally got it. It actually didn't take that long to figure out the basic way. Then I got stupid and forgot that %1 isnt the same as $1 so I was retarded. Anyways this will work with *.domain.com and then you can also check for stuff like *.domain.com* as well
You need to have wildcard DNS on. And you also most likely need to be able to create * ammount of subdomains from your host (many hosts have some way of checking this I think). A bit more about wildcard DNS at the bottom.
OK heres the rewrite code.
Code:RewriteCond %{HTTP_HOST} ^([^.]+)\.bigtoach\.com$ [NC]
RewriteCond %1 !^www$ [NC]
RewriteRule ^(profile|stats|gallery|work|etc)?/?$ /somefolder/somefile.php?user=%1&type=$1 [L,NC]
Quick examples http://changethisplease.bigtoach.com/ http://somethingelse.bigtoach.com/profile/
A few notes:
1. obviously change bigtoach\.com to what your site is.
2. You can change the rewrite rules on line 3 to whatever.
3. This will not do anything to www
4. Assuming your server is setup correctly it wont effect any of your existing subdomains either.
If you want the rule to go to different pages for different folders (ex: user.domain.com/profile/ goes to /folder/profileindex.php and user.domain.com/stats/ goes to /folder/statsindex.php) you can just substitue the filename with the rewrite (last line from above) like so:
Code:RewriteRule ^(profile|stats|gallery|work|etc)?/?$ /somefolder/$1index.php?user=%1 [L,NC]
And here is the wildcard dns stuff that I promised, Although the best thing to do would be to just ask your host.
If you dont know how to enable wildcard DNS contact your host, or if you are cool and dont really have a host, contact your DNS host and just ask em to enable wildcard DNS. If you are really crazy and host both, assuming you use BIND just add in *.domain.com.
enjoy kids!
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!
Last edited by Locke, August 25th, 2005 09:27 PM (Edited 1 times)
