Redirecting www to non-www urls

I was curious if there was a setting in Virtualmin where I could set all domains to default to using a non-www url and redirect the www url to the non-www url.

I know this can easily be done with Apache’s mod_rewrite individually for each domain, but I was hoping for a more general solution that would not require setting each domain individually.

Sorry for bumping my own post.

I have gone through and just tacked in a rewrite into all my domain in Virtualmin, but I am still hoping for a more global way of doing this. It seems like it would be a more common question considering Virtualmin’s seemingly loose handling of www and non-www requests.

Personally I use my DNS registrar (Namecheap) to do this at the DNS level.

@ redirect to
www a record

Of course you would need to set www as the redirect in your case.

@evad: Can you give an example of what exactly (hostname, IP, port, URL?) you’d like to have redirected where?

Redirecting a URL, as in web URL, requires a webserver to handle the request, which naturally means you need to configure the webserver to do that. Depending on what exactly you wish to redirect, you can probably make a global configuration entry in Apache to have it redirect requests to all hostnames accordingly.


I had not thought of using my DNS. I currently have both the www and @ records pointed to my IP address.


Virtualmin handles and requests in the same way by default. They both get directed to the public_html folder of the correct account.

I am looking to have always redirect to when it is handled. Right now I just have a mod_rewrite setting setup in a .htaccess file in each domain to make sure the requests are always redirected to

I tried creating a subserver for the www subdomain, but virtualmin told me it was already handling www requests and that creating the subserver was not necessary.

DNS does not offer “redirection” for browser URLs in that regard. What the registrar mentioned above does is either a simple CNAME, or they have a webserver running which does the redirection. URLs are handled by web servers, not DNS.

If you wish to do the redirection yourself, both the www and non-www variant MUST point to your IP. Except you’re going to use a webserver-based redirection service at your registrar.

Evad, may I ask why you wish to redirect ALL requests to I’m not sure if that is doable on a global basis in Apache. You might be best off adding the appropriate mod_rewrite directives to your server template, to have them auto-applied individually to each new domain.

This causes me some problems with single domain ssl certificates. It also messes up social share button counts. If someone likes the www homepage and someone else likes the non www home page, they are not treated as the same url, so each page gets a like count of one, instead of the homepage having a like count of 2.

Thank you for your help!