Different site for www and non-www (root) domain


I have virtualmin up and running and I’m really pleased with how easy it is to use. I have a bit of an odd requirement.

I have a domain, domain. com, and I’d like to present different sites on www.domain. com and domain.com. The www will go to a wordpress site and the “root” will go to a link shortner admin page.

When I created the virtualserver in virtualmin it automatically created the www. I tried changing the server template, but it still won’t let me create a www.domain. com site.

Is there any way to have two different sites one running on www.domain. com and one on domain. com?


OK, so if you removed the automatic ServerAlias www.${DOM} from the Server Template, and removed the www automatic DNS record, I’m surprised you can’t create a new server or sub-server for www.

You said it won’t let you…but what does it do? Is there an error?

When I try to create a new server or sub-server I get the error:

Failed to create virtual server : The domain name does not need to have www at the start

If I try and create it without the www, I get the obvious error

Failed to create virtual server : You are already hosting this domain

Ah, Virtualmin is maybe being too smart for its own good here.

@Jamie is there an easy way to convince Virtualmin not to prevent creation of both a www.domain.tld and a domain.tld (with different contents)? Assuming, of course, that Server Templates have been modified to remove the automatic www alias.

1 Like

Unfortunately not - it’s hard-coded to prevent creation of domains starting with www. because normally this is prepended automatically.

Maybe a better solution is to just create one domain, and to create a .htaccess file with a mod_rewrite redirect for the URL without the www ?

That’s not the goal here. OP wants two wholly separate sites. One with www one without.

There’s no way to do that currently, other than removing the check here : virtualmin-gpl/domainname-lib.pl at master · virtualmin/virtualmin-gpl · GitHub

This is not a good idea having completely different websites running on example.com and www.example.com.

@michaelsage Although, I can see that Jamie made a change that will allow root user to use virtualmin create-domain Virtualmin CLI with --skip-warnings flag to get initially desired result.

@Jamie, are you sure that removing other (i.e. not only /^(www)\./i) checks in valid_domain_name sub is a good idea?

Amazing, commenting out those 3 lines worked.

Is there any risk to adding the lines back in after I’ve created the site? I don’t need it for every site just this one :slight_smile:

Sure, you can add them back again …

1 Like

The next release of Virtualmin will allow you to override this check when using the create-domain API command to create a new server.

1 Like

Just out of curiosity why do you think this? This is a bit of an odd site in that the website for the site is different to the requirement for the “root”. The full website sits on www and a url shortner sits on the “root”. They don’t play nice if you put them on the same site, competing requirements, I tried putting the website in a directory /website and it just didn’t work very well. So this seemed like the best solution, but I’d love to hear what you think :slight_smile:

A lot of people and search engines will just use the domain.name without www and thus not get what you want them to.

Is the admin page for Wordpress admin?

Would a sub-server work for you?

Thanks for your reply :slight_smile:

The domain.name has a homepage redirect to www. The URL shortener application just didn’t play nice sitting on the same site wordpress, I was getting all sorts of redirect issues from both platforms. So for my use case I think splitting them is the easiest solution.

I don’t think I worded my reply well.

Would a subdomain work? eg instead of www.domain.com have wpadmin.domain.com

That way normal users will get your home page whether they got to www.domain.com or just domain.com and you cam do whatever you need by going to wpadmin.domain.com and nobody else needs to know about it.

remember to noindex the non public site so search engines don’t index it. Maybe thats inbuilt.

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.