Article directory
💡 Want to use HestiaCP Add subdomains in batches? One-click SSL certificate + .htaccess 301 redirect, fully automatic configuration tutorial is here! 🚀 Done in 5 minutes, make your website more secure and efficient!
“One operation, hundreds of subdomains can be easily handled?”
Many webmasters encounter a tricky problem when using HestiaCP to manage servers:
How to add multiple subdomains in batches and automatically enable SSL and 301 redirects?
If you add them one by one manually, it is not only tedious but also prone to errors.
So, now I will teach you one Automatically add subdomains + SSL + 301 redirects in batches method, so that you can get all the configurations at once!

📈 How to add subdomains in batches
1. Use HestiaCP command to add subdomains in batches
HestiaCP provides v-add-web-domain command to quickly add a subdomain.
Using the following script, you can batch add HTTPS certificates for multiple subdomains at once and enable HSTS.
USER="youruser"
DOMAIN="yourdomain.com"
for SUB in en fr de es it pt nl ru jp cn
do
FULL_DOMAIN="$SUB.$DOMAIN"
v-add-web-domain $USER $FULL_DOMAIN
v-add-letsencrypt-domain $USER $FULL_DOMAIN
v-add-web-domain-ssl-force $USER $FULL_DOMAIN
v-add-web-domain-hsts $USER $FULL_DOMAIN
done
2. Configure subdomains in batches .htaccess 301 redirect
Batch creation .htaccess File to redirect all subdomains to the subdirectory of the main domain.
for SUB in en fr de es it pt nl ru jp cn
do
FULL_DOMAIN="$SUB.$DOMAIN"
HTACCESS_PATH="/home/$USER/web/$FULL_DOMAIN/public_html/.htaccess"
echo "RewriteEngine on" > $HTACCESS_PATH
echo "RewriteCond %{HTTP_HOST} ^$FULL_DOMAIN$ [NC]" >> $HTACCESS_PATH
echo "RewriteRule ^(.*)$ https://www.$DOMAIN/$SUB/$1 [L,R=301]" >> $HTACCESS_PATH
done
📅 After running, all subdomains will be automatically redirected to the corresponding directories of the main domain name!
✨ One-click automation script
If you don't want to enter the command manually, you can use the following One-click batch adding subdomains + SSL + 301 redirect script.
🔎 Script content
#!/bin/bash
USER="youruser"
DOMAIN="yourdomain.com"
SUBDOMAINS="en fr de es it pt nl ru jp cn"
for SUB in $SUBDOMAINS
do
FULL_DOMAIN="$SUB.$DOMAIN"
v-add-web-domain $USER $FULL_DOMAIN
v-add-letsencrypt-domain $USER $FULL_DOMAIN
v-add-web-domain-ssl-force $USER $FULL_DOMAIN
v-add-web-domain-hsts $USER $FULL_DOMAIN
HTACCESS_PATH="/home/$USER/web/$FULL_DOMAIN/public_html/.htaccess"
echo "RewriteEngine on" > $HTACCESS_PATH
echo "RewriteCond %{HTTP_HOST} ^$FULL_DOMAIN$ [NC]" >> $HTACCESS_PATH
echo "RewriteRule ^(.*)$ https://www.$DOMAIN/$SUB/$1 [L,R=301]" >> $HTACCESS_PATH
done
systemctl restart hestia
systemctl restart nginx
systemctl restart apache2
echo "🎉 所有子域名已成功添加,并启用 SSL + 301 重定向!"
🔧 How to use
- Copy the above code and save it as
batch_add_subdomains.sh - Run the following command to give the script execution permissions:
chmod +x batch_add_subdomains.sh - Run the script:
./batch_add_subdomains.sh
💡 Conclusion
✅ Add subdomains in batches, one-click execution to avoid duplication of work.
✅ Automatically configure SSL, HTTPS is enabled for all subdomains.
✅ 301 redirect, Promote SEO Friendship.
✅ Fully automated script, even novices can use it easily.
Using this method, your HestiaCP server will become more efficient and professional, allowing you to focus on more important business instead of wasting time on tedious manual operations.
If you find it useful, don’t forget to share it with your friends!
🚀 Make your server management simpler and more efficient, starting now!
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ )'s sharing of "How to add subdomains in batches and configure SSL + .htaccess redirection in HestiaCP?" may be helpful to you.
Welcome to share the link of this article:https://www.chenweiliang.com/cwl-32637.html
To unlock more hidden tricks🔑, welcome to join our Telegram channel!
If you like it, please share and like it! Your sharing and likes are our continuous motivation!