-3

I created subdomain like this user2.example.com.

127.0.0.1       localhost
127.0.0.1       user2.localhost

and this is the static one

but i need the user2 will b the dynaimic for example if i was registerd with abc(username) my website should b like this abc.example.com

Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111

3 Answers3

1

What you are search for is a Wildcard Subdomain. You need to register one at your Domain Reseller (*.example.com), but it is not supported at most hosters, i know. For testing on localhost, you need a custom DNS Server. Take a look at this Answer.

Then it is depended on the Webserver.

For Apache:

<VirtualHost 111.22.33.55>
    DocumentRoot /www/subdomain
    ServerName www.domain.tld
    ServerAlias *.domain.tld
</VirtualHost>

For Nginx:

server {
  server_name example.com www.example.com;
  root www/pub;
}

server {
  server_name ~^(.*)\.example\.com$ ;
  root www/pub/$1;
}

For IIS:

<rule name="CustomRule" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
  <match url="*.aaa.bbbb.com" />
  <action type="Rewrite" url="http://aaa.bbbb.com/{R:0}" />
</rule>
Community
  • 1
  • 1
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111
0

If you're running your website on Apache its better to check URL Rewriting Guide from the Apache documentation out. Also you can try a thing like this :

RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
RewriteRule ^/(.*)$           http://www.domain.com/%1/$1 [L,R] 

If you're running your website on Nginx you can try this:

server {
  server_name ~^(.*)\.domain\.com$ ;

  rewrite ^ http://www.domain.com/$1 break;
}
OnlyMAJ
  • 819
  • 8
  • 21
0

First, we need to configure our DNS settings to make all subdomains resolve to a single address. Then configure Virtual Hosts in the Apache Configuration to save our page and Remember the wildcard.

Check this tutorial step by step

Don
  • 69
  • 4