I want to allow my users to create their own wild card domain. For example, If someone creates nick.domain1.com, it would automatically forward to nick's profile. or dennis.domain1.com, it would automatically forward to dennis' profile. How would I begin to do this? Thanks!
I use a similar system for a Multiforums script I developed. To enable the wildcard DNS on your server, follow these directions. That will set up the wildcard DNS on your server. Now, to actually enable the redirect edit the code below and paste in your .htaccess file in your public_html folder: Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$ [NC] RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.yourdomain\.com$ [NC] RewriteRule (.*) /folder/$1 [L] Code (markup): So in this case, anything.yourdomain.com redirects to yourdomain.com/folder/anything. Be sure and change the yourdomain parts to your domain and the .com to the domain extension. The slashes are required. So, you may try something like: RewriteRule (.*) /profile.php?id=$1 Code (markup): To redirect to yourdomain.com/profile.php?id=anything Hope it helps, Brandon
But how I need to check the wild card string with my database. For example, for nick.domain1.com, I need to grab the "nick" string to see if it's in my database. If "nick" is there, I would grab its id and forward the nick's profile.
In your profile.php page or wherever you want to display the data, you would do something like this: $ref = $_SERVER['HTTP_HOST']; //Get current domain... //Are we using www in the domain? if(strstr($ref,'www.')) { $ref = substr($ref, 4); //Strip first 4 characters from the string, remove www. } $parts = explode(".",$ref); // Split $ref into parts // Grab the first part, this only contains the username, not the .com or filepaths... $ref = $parts['0']; //Let's clean things up and remove slashes and non alpha-numeric chars $ref = preg_replace("/[^a-zA-Z0-9s]/", "", $ref); // Protect database $ref = mysql_real_escape_string($ref); PHP: Then after that the user's name is stored in $ref for you to use. Then simply query your database and if the user exists pull up their profile info. Brandon