[REQ] [How-to] Unique subdomain for each member profile

olaechea

New Member
[How-to] Unique subdomain for each member profile

Hi All

As for Blogs and Free hosting websites we see every user in the website given a unique subdomain, something like user.example.com, Did you ever wonder how this is done? Is the webmaster waiting for new users to activate their sub-domain manually, of course not this must be done automatically, infact automagically
in the following lines you will be learned how to do that in your website.
WARNING: The following tutorial (in Step 1) contains some slight configuration with the webserver, you should ask your webhost to do them for you, or, if you have priviliges to the server be cautious or you will put yourself in endless problems
Again if you dont know how to do that ask for a pro to do it for you.
NOTE:
1- montadaphp.net is to be replaced with your Domain name allover the tutorial.
2- 66.66.66.66 is to be replaced by your website IP (either Shared or Dedicated) allover this tutorial.


Demo:
See what this page leads to: coder.montadaphp.net
or this: amine.montadaphp.net

Step 1: Server configuration:
NOTE: be sure to take a backup of the files:
/var/named/montadaphp.net.db
/usr/local/apache/conf/httpd.conf


* Execute this command using your Shell program (you can download one here):
Code:
PHP Code:
pico /usr/local/apache/conf/httpd.conf
Note that the path of the file may vary accoring to ur system or config, if you dont find the file in the specified path use the command (locate httpd.conf) to find the right path for you.

Search for something like that:

281-screen1.gif


Where you should replace:
Code:
PHP Code:
ServerAlias montadaphp.net www.montadaphp.net

with:
Code:
PHP Code:
ServerAlias montadaphp.net www.montadaphp.net *.montadaphp.net

then save the file and Close..


* Then execute this command in Shell window:
Code:
PHP Code:
pico /var/named/montadaphp.net.db

Add the following line anywhere in the file:
Code:
PHP Code:
*.montadaphp.net. IN A 66.66.66.66

Save and close the file
Restart your Named & httpd services
or restart the whole webserver


Step 2: Writing .htaccess file to redirect subdomains:
Create a new file named .htaccess or edit ur existing file (if there is one) and add the following code:
Code:
PHP Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteCond %{HTTP_HOST} ^(.+).montadaphp.net
RewriteRule ^(.*) http://www.montadaphp.net/member.php?username=%1 [R=301,L]


and upload it to your forum's root (usually public_html)

link: http://forum.egypt.com/enforum/articles-f145/how-unique-subdomain-each-member-profile-6360.html
 
Top