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

1 Like

@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:

hey @jorgepala do you mind to elaborate about this, i donā€™t understand you.

This is a 3 year old topicā€¦

2 Likes