Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically create subdomains with apache and spring

I am developing an application using Spring , jsp and Apache 7.0 server, now suppose i have register domain such as "www.example.com" and in my application the user fills the registration form in which the user is ask to enter his url to name such "123" as soon he submit the form after filling details i want to redirect the him to the newly created URL now in our case "123.example.com"

Now at this movement i have to create sub domain in my code itself before he gets redirected. I have gone through google not find much.

Any help

Thanks in advance.

like image 200
ASUR Avatar asked Jul 24 '13 10:07

ASUR


2 Answers

You need to enable wildcard subdomains. That will allow your app to respond to requests from anything.yourdomain.com. Next, your app needs to define a route which converts the subdomain to a variable so that you can use it to scope your database requests to their account. Once the user has their custom subdomain set up, they should register their domain under their account (so that you can look up the account by domain instead of subdomain) then create a CNAME DNS record which points to their subdomain. These principles apply regardless of the language/framework.

like image 131
Musa Avatar answered Sep 23 '22 10:09

Musa


You could use a wildcard cname (i.e *.example.com) then use a spring interceptor (https://dzone.com/articles/using-spring-interceptors-your) to determine which subdomain the user requested.

like image 39
drei01 Avatar answered Sep 24 '22 10:09

drei01