Create subdomain

Estimates, I need you to tell me how to create the subdomains in the panel (client.example.com).
Is this within the domain already created (example.com) as in other CPs or are they managed as a separate domain?

yes, a subdomain is added as a regular web domain

@jorgepala if you want to have a subdomain pointing to a subfolder below a regular web domain, you could simply add it as alias and use .htaccess to redirect (if using apache2) or add a custom config to your vhost. or you set it up as seperate domain and link the folder :wink:

Sorry to open an old thread!
Due to legacy reasons, I also need a subdomain as a folder in the main domain.
I’ve added the subdomain as a domain, and added an A record in the DNS of the main domain, but when I try to change the document path, “Error: Error: target dir outside of target domain dir”.
How do I add an alias? Where? in the text box that contains ‘www’ ?

For anyone having the same problem:
An alias is where you add the www (edit domain). Don’t forget to renew the Let’s Encypt SSL with the new alias. (don’t know where,yet).
To redirect the subdomain to a folder, just add this code:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.domain.com
RewriteRule ^(.*)$ /subdomains/sub/$1 [L,NC,QSA]

(taken from https://stackoverflow.com/questions/10642426/htaccess-rewrite-subdomain-to-directory)

Make sure the folder exists

You can create a subdomain and put a custom route when creating it, it is one of the new options in hestia, at least it works for me.
domain.com path “/home/user/web/domain.com/public_html/”
subdom.domain.com path “/home/user/web/domain.com/public_html/subdom”

2 Likes

Also make sure the folder exists:) Hestia doesn’t create the folder for you.

2 Likes

The code @noxtras shared lead to internal server error for my subdomains
Found another one on VestaCP docs

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI}::%1 !^/([^/]+).*?::\1
RewriteRule ^(.*)$ /%1/$1 [L]

This one does the job quite well for me, Guess I’d share.
Hope it helps :slight_smile: