Is it possible to handle sub-domains in Django without having each of them registered with registrar, provided i have purchased and setup the domain?
Suppose i own example.com
. I have purchased it, and setup it to point to my website at some hosting service. But, did not add a sub-domain blog.example.com
. Then, can i serve some webpage at blog.example.com
?
How request.subdomain
in django-subdomains
(doc) library is supposed to be used?
After all, I found an answer.
Instead of registering each subdomain separately with the registrar, We should register a wildcard DNS entry for the domain so that all expected subdomain will point to that one. Then configure the web server to catch all subdomains. An example I got for nginx is:
server {
server_name example.com www.example.com;
root www/pub;
}
server {
server_name ~^(.*)\.example\.com$ ;
root www/pub/$1;
}
Then using django-subdomains
library (doc) we can get the sub domain from the views or middlewares. Based on that we can redirect the view to wherever wanted using django. This is the vague idea. Anyone experienced please elaborate. An example, http://sarahah.com gives a sub domain for every user. This is where I found this is possible. But don't know how they implement it.
A discussion is found in this reddit page.