A
A
Alexander2011-04-30 08:04:20
Domain name market
Alexander, 2011-04-30 08:04:20

Create a subdomain for an account

Tell me how to implement so that when registering on the site, a subdomain of the form is automatically created: username.site.ru (for example, as on Habré).
If there. links where you can read, I will be grateful.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
E
ertaquo, 2011-04-30
@Palehin

It is not necessary to actually create subdomains. You can set up the site so that everything goes through the main domain, and already there you can check where the user has applied. Alternatively, you can set up .htaccess like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+)\.([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ %2/%1/$1 [R=301,L]

K
krotish, 2011-04-30
@krotish

Read on habre.
If I understand correctly, then, for example habrahabr.ru/blogs/webdev/101585/

H
Hint, 2011-04-30
@Hint

No need to create subdomains at the time of registration.
A common entry for all subdomains (*.example.com) is added to DNS. Something like:
* IN A 192.168.1.1
The server settings indicate that it should process requests to subdomains. For httpd, something like: For nginx: That is, requests from all subdomains go to the web server. And then the script parses the HTTP_HOST header and outputs the corresponding content.
<VirtualHost *:80>
DocumentRoot /path/
ServerName example.com
ServerAlias *.example.com

server_name .example.com

A
ahilles, 2011-04-30
@ahilles

I did this on mod_rewrite.

P
Puma Thailand, 2011-04-30
@opium

The easiest thing to do in DNS is to write down *.mydomain.com cname mydomain.com
In the web server you raise a virtual server that processes *.domain.com
In scripts, catch the name of the domain by which they are accessing and display the necessary content.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question