Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a subdomain with username as subdomain name?

I have referred other related question but they are not clear to me. Please explain me: How can I make subdomain in PHP?

Example :

http://www.domainname.com/page.php?usname=sundar

I want change the link to this

http://sundar.domainname.com

Is this possible in PHP? Or any other way to do it?

like image 540
ananth Avatar asked Aug 01 '11 08:08

ananth


2 Answers

You may create a virtual sub domains and then you can redirect it with .htaccess.

You also have to create

A Record look like this

*.exmple.com A 127.0.0.1 or your IP

in your DNS.

Then add something like this in your .htaccess

RewriteRule ^([aA-zZ])$ home.php?username=$1

RewriteCond %{HTTP_HOST} ^(^.).mywebsite.com
RewriteRule (.
) home.php?username=%1

It should help

like image 68
vsuhov Avatar answered Sep 22 '22 22:09

vsuhov


my way:
you will have to create a wildcard subdomain and point it you your domain.

http://www.easymodrewrite.com/example-subdomains

Then you can parse $_SERVER['HTTP_HOST'] for querying out the user name .

if you are under hosting plane, you can probably create it from the GUI.
Else, you need to via the APACHE panel and configure the DNS.

like image 39
fatnjazzy Avatar answered Sep 19 '22 22:09

fatnjazzy