How to create automatic subdomains from a form?

Asked

Viewed 3,748 times

9

I am developing a large system, which already serves almost 30 companies in the state and some more are to join.

The system is accessed by companies from this url:

  • meudomínio.com.br/business1
  • meudomínio.com.br/loading2
  • meudomínio.com.br/lending 3

I’d like to know how to do the "Automatic subdomain" which is kind of like this here:

Subdomínio automático por formulário

I enter the name of the company and it passes to access the system from company1.meudomínio.com.br

  • 1

    This is an Apache configuration. I don’t see how a system that runs under Apache itself could change a configuration of it. My suggestion would be to keep the domains saved in some bank and use a cron to search for the domains created and create them in Apache settings.

  • Can you confirm which web server you are using? As @rodrigorigotti said, the ideal would be to schedule a task that changes the server settings, but how to do this depends on the server used, (and depending on the case, also the operating system).

  • Use cPanel, follow an ss of the server settings: link

  • 1

    First you need to have a database with the list of subdomains. Then just create a *wildcard subdomain .dominio.com.br pointing to a file testa_subdominio.php. When the user type meulogin.dominio.com.br, the server calls testa_subdominio.php which connects to the BD and loads the page to login "meulogin" or error 404, if the login does not exist or is invalid.

  • If you are using Cpanel, you can use this Cpanel library that allows you to create subdomains by passing PHP parameters. https://github.com/CpanelInc/xmlapi-php

1 answer

3

Allowing apache to create folders... of dynamics this is the best because internal paths are fixed alone, without impact to php for example... http://httpd.apache.org/docs/2.2/vhosts/mass.html#simple

But I already used the text file method, it had no graphical interface, to administer, but the client could upload a text file to ftp in which he put the domain and the root folder and apache went up the site in the act, according to the apache site:

RewriteEngine on

RewriteMap lowercase int:tolower

# define the map file
RewriteMap vhost txt:/www/conf/vhost.map

# deal with aliases as above
RewriteCond %{REQUEST_URI} !^/icons/
RewriteCond %{REQUEST_URI} !^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
# this does the file-based remap
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/docs/$1

RewriteCond %{REQUEST_URI} ^/cgi-bin/
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/cgi-bin/$1

http://httpd.apache.org/docs/2.2/vhosts/mass.html#Xtra-conf

  • Thanks @Brenozan. Just a question with this: this map file "vhost.mp" I have to create? What file template?

  • 1

    yes you create... in practice you can also use mdb or mysql (DO NOT USE!), just need to meet the map compatibilities of rewrite http://httpd.apache.org/docs/current/rewrite/rewritemap.html#dbm. I really suggest you use the simple.. the others give a headache with the paths and security issues of the applications within them..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.