Best route to setup website as "www."

Hi folks,

EDIT: For clarity, I replaced posts 1 & 2

I have Virtualmin setup with a server titled “”. I allowed it to create a website during the setup process and it has created the folder “/home/{username}/public_html” for serving content to Apache. I have popped a “Hello World” HTML file in here for testing

Here’s what I’m seeing…

If I browse to “” - it stays on the naked domain and opens Hello World
If I browse to"" - it keeps “www” in the URL and opens the same and opens Hello World

If I look in Webmin > Servers > Apache Webserver, I have the following:

I was a little confused about the two default Apache entries in the image as it was serving the Apache config page until I reloaded. The three Apache entries in the image above remain but it now loads “Hello World” for naked and “www” requests

While I haven’t specifically created a “www” sub-domain or server, considering I can browse to it, how would I go making this “www” sub-domain the primary in Apache as in re-directing requests to the naked domain to “www”… keeping in mind that I will be activating Lets Encrypt afterwards and forcing HTTPS

Also, is there any further configuration needed on the default Apache stuff? I don’t want the Apache config page appearing again and I’d like to clear out any old directorys which were previously serving content



Not sure I totally understand, but if I get this correct you are saying that you want anyone who travels to = to be forwarded to

You don’t create a server for each, it will take care of showing both for you. So in your DNS manager you will see that virtualmin has already created an A record for you that points to www. and it has already handled it.

If what you want is to only show WWW when someone travels to your website, this is done with .htaccess file using mod_rewrite and not within Virtualmin.

#Force www: RewriteEngine on RewriteCond %{HTTP_HOST} ^ [NC] RewriteRule ^(.*)$$1 [L,R=301,NC] #Force non-www: RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] RewriteRule ^(.*)$$1 [L,R=301]

This is also how you force https, once you go https, it will load both https or http natively, although, I think that Virtualmin has a checkbox to allow you to force https without having to add this code.

This is the typical code to force https only once you have a cert

#Force https RewriteCond %{HTTPS} !=on RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]

So if your final intention would be to have only WWW and forced HTTPS then it would look like.

#Force HTTPS and WWW RewriteEngine on RewriteCond %{HTTP_HOST} ^ [NC] RewriteRule ^(.*)$$1 [L,R=301,NC] RewriteCond %{HTTPS} !=on RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]

This is good to do for SEO also, it doesnt neccisary help you show better in google because google handles having both just fine, but allows you to have less to manage in your account.

If you’re not sure what .htaccess is, do some research on it, its a very powerful document and a lot can be done with it. You can actually had it react to different scenarios.

The htaccess file goes in the same folder as your index page normally. If your using an application like drupal or joomla or wordpress, it will have an htaccess already and you just need to edit it, if your are building your own website, then you will need to make one. its a hidden file so it can get lost on your filesystem if you don’t have “show hidden files” turned on in windows.

simply name the file ( .htaccess ) upload to your websites ( public_html ) folder with your index.html or index.php page and boom, your in business.

Hope this helps,

Hi Kyle,

Thanks for the response… you’ve explained my question better than I could myself!

Yes, I wish to have any visits to the naked domain “” re-direct to “www.mydoma…” and as I’ll be forcing SSL on top of this, it really all re-directs to “https://www.mydoma…”. I’ve always understood the correct term for this to be a 301 Re-direct but no matter what changes I made within the control panels, I couldn’t get the naked domain to re-direct. As for SEO, I’m familiar with adding both version of a domain to Google Webmaster and setting one as primary so SEO isn’t my concern - just I want to be sure my visitors always end up at a “www.” URL and not a mixture of both

I’m a bit surprised to see you mention editing the .htaccess file to achieve this. While I’m okay with doing this, I had imagined that having Webmin / Virtualmin meant I could make all these changes through the interface and it would look after editing the under-lying files for me. My only concern with editing files directly is that I would make a change that Webmin can’t understand or see which could cause problems elsewhere

Just on your point about DNS too - if it means anything, I deselected BIND when I setup Virtualmin as having read some other postings here, I understood that I didn’t need it for my use case. I’m not running DNS on the server either… I literally have my two records setup with my domain registrar pointing the naked and the www to the IP of the server

Finally, I’ve done a bit more digging on SSL as I had some trouble getting it working in a past attempt. After a bit of reading, I enabled “SSL Website” under Virtualmin > System Settings > Features and Plugins and also, I enabled “SSL” for Apache under Webmin > Servers > Apache Webserver > Global Configuration > Configure Apache Modules. I have enabled Lets Encrypt for the naked and “www” domain and while I still haven’t managed to get the HTTPS versions of the site loading, I’ll take your advice above and keep working through it



Hey Conor,

To be honest Im very fresh to Virtualmin, So I don’t know much about it or linux but I have been doing web design for about 12yrs now. I can assure you that adding the above code will not break virtualmin in any way. Your .htaccess is designed for this. But, it is also possible that the Virtualmin team has devised a way to do this method via an automated process, but I doubt it, They would have to have come up with a way to edit every website’s primary htaccess file and I’m not sure how that could be automated. Then again there is possibly ways to do it via apache system, but those I am not aware of since I am fresh to linux.

It’s more likely that they have a method for forced https than for forced WWW. But again, I’m not sure.

Mod_rewrite is the standard method for doing this and is the way I have always done it. If you google “How to force Https” or “How to force WWW” you will get all results pointing toward editing your .htaccess file. Although I have never been my own server before. If you are hosting with other people than options are obviously more limited and restricted to their systems.

Mod_rewrite isn’t actually a 301 redirect, that is more or less for a permanent “location” change. 301s are typically used for when a website or a page is relocated and you want to tell either a search engine or someone that may have an old link to that page where to go. Especially for search engines because when they see it, it will force them to update their listings of that address. 302’s are for links that you don’t want search engines to change the address of but give the same results as a 301 in terms of redirection. 301 redirects and 302 redirects are also done via the .htaccess file. Whereas Mod_rewrite simply “rewrites” the information that a visitors sees for the current location. With the code above, it finds the location that the user if visiting then fixes the formatting the way you want and loads that variant of it instead. This essentially keeps people from seeing a particular version of a page either for security / cleanliness or SEO. Mod_rewrites will also affect SEO for the better, especially if they are implemented before the crawlers start indexing pages, If they have pre crawled the site, they will update the next time they crawl after the rewrite has been done. Of Course you can always force a crawl via Webmaster tools for that particular engine.

Hopefully someone from Virtualmin can chime in and let you know if there is an automated process for this.

For the HTTPS, If you have already created a cert for your domain, and its working. Even though you dont have “forced” https setup yet, you should be able to just navigate to your website at and it should work. If it doesn’t than there is a bigger problem at hand that I can’t help with and you will want to get that fixed before you force https.

I figured out the dual nameservers with bind setup and did a writeup on it for others if anyone ended up googling it in the future.

Hope this helps, sorry I dont know enough about virtualmin to say if there is a method for this within their system.


Many thanks Kyle

Okay, after yet another server restore I finally got a HTTPS “Hello World” appearing for the naked and www versions of the domain. I was previously enabling Lets Encrypt inside Webmin when it seems I am meant to enable it for the specific virtual server through Virtualmin > Server Configuration > Manage SSL Certificate. I can’t say I’m entirely comforable with the SSL setup but it works so far and checks out with the SSL Labs test

Next challenge was to figure out the .htaccess changes. I gather Webmin / Virtualmin doesn’t use or create a .htaccess by default so I’ve went into Apache modules and enabled rewrite. I then tweaked your content above and pasted it into my root and I’m happy to anounce that everything now re-directs to https://www:slight_smile:

I’ll pass on messing with any DNS stuff for now as I don’t think I need to. Again, I literally have my registrar pointing 2 A records at the public IP of my AWS instance and so far, nothing has complained. I’ll probably get mail up and running on the instance later on so I’ll review it all then

Now, back to getting Wordpress up and running… i.e. what I happily working on before I decided I needed Webmin and Virtualmin! This is some can of worms I’ve opened upon myself! Like yourself, I’m fresh with Webmin but unlike yourself, I don’t have 12 years of working with websites to fall back on! I won’t say I’m completely lost with web stuff… I know in head what does what, what goes where… but putting it into practise is taking much trial and error. All said, if this steep learning curve means getting out of doing the whole Christmas thing, I’ll happily take it on :slight_smile:

Again, many thanks for your help here Kyle… much appreciated



Sure thing, No problem.

I’m glad it all worked out for you.

Best of luck in your ventures.

Wordpress is another beast entirely, you will have just as much fun modifying your CMS, wordpress is good about updates and is a great choice for a first website that requires content management.

Take care :smiley: