Adding features to Virtualmin template

Hi! is a virtual server containing phpMyAdmin is for webmail

I host a few domains. Each time I create a VH for a new one I have to manually add an alias like




in their respective at httpd.conf

Is it possible to add those alias from the template each time a new VH is created?
Thank you

Hmm, I don’t believe there is an option for specifically that – but there is an option for executing a script during the creation of a Virtual Server.

What you could do is create a script that uses the command line tools to create the aliases (and anything else you might want) during the setup of any new Virtual Servers.

You can set that up withing System Settings -> Module Config -> Actions Upon User and Server Creation -> “Command to run after making changes to a server”.

You can get a listing of what options are available to you on the command line by typing the command “virtualmin”.


I don’t know how to handle this.
modify-web is an option I found.

virtualmin modify-web [args]

In command line what I need is something like this:
cp httpd.conf httpd.conf.BACK; sed -i ‘s/ServerAlias sql.newDomainAlias/’ httpd.conf

In other words: make a backup of httpd.conf and substitute the text
ServerAlias sql.newDomainAlias

So the second alias listed alias would be the new one.
The first one already exists.

Thank you

Rather than “modify-web”, it sounds like what you want is a new Alias Server.

So you could use something like:

virtualmin create-domain --domain --alias

Can I test it from command line?
Does this command ‘contain’ httpd restart?

I’m not sure whether that restarts Apache or not. The best I can offer is that if it doesn’t work, try restarting Apache :slight_smile:

That’d either be “/etc/init.d/apache2 restart” or “/etc/init.d/httpd restart” depending on your distro.

To test it from the command line, you could use a tool like links or wget.


My question was about adding a command line into a virtualmin template for new virtual hosts.
That should be automatic.

Yeah, the webmail and admin aliases are added automatically by Virtualmin.

But, you could add something similar by editing the template in System Settings -> Server Templates -> Default -> Apache Website.

However, if you’re getting the message “You are already hosting this domain” – are you sure the address hasn’t been setup somewhere else already? That could cause trouble if it has been :wink:


I give up on this line.
The option create-domain displays ‘You are already hosting this domain’.
There is an option modify-domain but it does not have an alias suboption.

Maybe it would be easier to add to the template something like

RewriteCond %{HTTP_HOST}
RewriteRule ^(.*) [R]

You have some similar rules for other subdomains like webmail but I could not find where to add this rewrite rule.

RewriteEngine on
RewriteCond %{HTTP_HOST}
RewriteRule ^(.*) https:/ [R]

I also have researched in

virtualmin get-template --id 0

Thank you

Well. I only am trying to add Alias into directory.

Under “Apache” template do not appear those rewrite conditions.
ServerName ${DOM}
ServerAlias www.${DOM}
DocumentRoot ${HOME}/public_html
ErrorLog /var/log/virtualmin/${DOM}_error_log
CustomLog /var/log/virtualmin/${DOM}_access_log combined
ScriptAlias /cgi-bin/ ${HOME}/cgi-bin/
DirectoryIndex index.php index.html index.htm index.php4 index.php5
<Directory ${HOME}/public_html>
Options -Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All

<Directory ${HOME}/cgi-bin>
allow from all

I created a testing VS that contains
RewriteEngine on
RewriteCond %{HTTP_HOST}
RewriteRule ^(.) [R]
RewriteCond %{HTTP_HOST}
RewriteRule ^(.
) [R]

Anyway I might add my rewrite conditions in Apache template but I should have to have ‘RewriteEngine On’ twice in httpd.conf

No answers for this?

It didn’t sound like your latest post contained a question :slight_smile:

I’m not quite sure I’m following what you’re trying to do there – but if you’re referring to the “” Alias you’re trying to add giving you the “You are already hosting this domain” message – are you sure that isn’t setup somewhere else within Apache already?


Hi Eric,
Yes, this is an invented name, just to test.

The remaining question was about where do you have set those rewriting conditions in default template. I couldn’t find them on any place.
I would add to webmail and admin this
RewriteCond %{HTTP_HOST}
RewriteRule ^(.*) [R]

But I don’t know where.
Thank you!

You should only ever see “You are already hosting this domain” when adding a domain that’s already defined in Apache.

I’d double, perhaps triple check that it’s not in there anywhere, as I suspect it’s hiding in there somewhere :slight_smile:

But, if you’re super-super-super sure that it exists no where in Apache, then it’s a bug, so you may need to file a bug report in the Support Tracker for that.

Regarding the mod_rewrite stuff – the webmail and admin parts are automatically added by Virtualmin that’s not defined in any template.

Virtualmin will add it if the “Redirect webmail.domain to Usermin” and “Redirect admin.domain to Usermin”
options are set to “Yes” in System Settings -> Server Templates -> Default -> Apache Website.

To add in additional directives, you could put them in “Directives and settings for new websites” on that same page.


I know that about “Directives and settings for new websites”
I was asking that I can input those directives but “Rewrite engine on” will be placed twice and this is not good.