Configure Virtualmin/htaccess to access files via subdomain?

Hi all,

I recently set up a new server, for my wordpress (among other things).
The address is; this works correctly.

I’ve also set up a sub-server, – as you can see by going there, it just redirects you to the main blog, and specifically to the Not Found page, which would be correct for any other non-working address. (edit: actually it doesn’t do that, it just displays the normal page without changing the URL and with some stuff like fonts not displaying properly because of missing CORS policy…)

My goal is for to provide access to (you guessed it) files, so, say, or would just lead to the relevant resource. I’ve put my files in the directory created by Virtualmin, /home/robin-v/domains/ but I can’t find a way to access them.

I don’t know if what I’m trying to achieve should be done via .htaccess or an option inside Virtualmin. I couldn’t find any option in Virtualmin that seemed related to this. Here is my htaccess, for reference:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www.)?$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

This is in the main server’s htaccess. Whatever I put in the sub-server’s public_html directory is not accessible, so htaccess files there don’t do anything.

Anyone know what I should do at this point?


Is your sub-server DNS resolvable?

Hi Peter,
I’m not sure what you mean? I have an A record for with the same IP as my main server. Do I need to edit something in my VPS’s hosts file?


So it looks like both “” and “” resolve, so that’s good. When I go to either of the domains, it shows the same page, is that intentional?

It’s not actually the exact same page. Like I said, loads my wordpress blog but with some errors, namely all the resources like fonts and images don’t show up, because they are in the wp directory. So, to be clear:

  • correctly loads wordpress along with the resources stored in the wordpress directory, which is inside the server’s public_html;
  • loads wordpress too, I’m not sure why, but because that server’s home directory is different, it can’t fetch the fonts and images because I have not set up CORS headers;
  • the intended behaviour is that throws a 403, and something like loads that image (which is an actual image currently sitting in /home/robin-v/domains/

does anyone have an idea on how to fix this? :slight_smile:


If you’d like, we can setup a formal support session and I can diagnose what is going on, and answer any other questions you have. Contact me if you’re interested.

Thanks, I need to do a bunch of stuff on my server and if after all of that it’s not resolved, I’ll PM you :slight_smile:

In the meantime, if anyone sees what might be causing this based on the info in the thread, feel free to share! I’ll update if I fix it myself.

Hey mate, did you manage to solve your problem?
I’m also trying to create a Cookie-Free domain just like you, one sub-domain to point to wp-contents directory.

I’m following this guide:

But it shows how to create subdomain in cPanel (so much simpler, why can’t VirtualMin be as simple as that?) and I have no clue how to do that in VirtualMin.

This is the first (somewhat) good argument I’ve ever heard (in 14 years!) for the way cPanel handles what it calls “subdomains”. :wink:

I’ll look into adding a feature for this, but I don’t want to call it “subdomain” even though that’s what cPanel calls it; it confuses too many people. Maybe something like “Sub-directory Domain” (since there’s no reason it has to be a subdomain name, and I’ve always found it utterly bizarre that cPanel conflates the two concepts…you could point any name to a subdirectory, and it’s dumb to give people the impression that they have to put subdomain named sites into a subdirectory of the parent domain). There actually is a “subdomain” feature in Virtualmin (at least, I don’t think we ever removed it), modeled after the cPanel feature. It’s hidden in Virtualmin by default, and I’ve always hated it because it’s really stupidly named. But, I don’t think we ever got rid of it, and maybe it’s time to consider renaming it and bringing it back into the defaults.

Believe me or not, but I went to that “super-hidden-freaking-menu” and enabled the “Sub-domain” stuff. But even with that think enabled, I was having trouble to create a virtual server as “sub-domain”. I mean, I was able to create it, but it was not directing to the folder I want.

Some people also complain about “Access Denied” when using this sub-domain stuff. There is something bugged when you have to use this (maybe because it was forgotten and never updated, so it may be using incorrect automation and screwing things up), because you have to set virtual directory manually but Virtualmin keeps switching between Apache and FGCI (I think that’s the name), and it screws with files/folders permissions.

Please, take a look at this link and see if you’re able to find out what is wrong and if you can fix this “sub-domain” stuff, and maybe even make it enabled by default for some newbies. I know, it may look dumb, but that’s why so many webhostings keeps using cPanel, even it’s wrong, it keeps things simple (even after 10 years later).

I’m not sure if this is the case that this menu is “broken” (or at least partially broken), but even using this so called “hidden menu” I still can’t use it properly like in other webhosting panels (cPanel, VestaCP…)

Btw: If any english sentence is confusing and you couldn’t figure out what I meant, just tell me and I’ll try to re-phrase that. I’m a bit rusty in English :P.


I’m having the same issue.

My websites, for example,,, etc… need to access images on (hosted on the same server) but I get this error:

Access to Font at ‘’ from origin ‘’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘’ is therefore not allowed access.

I have added this as a .htaccess file in the public_html of the

Header add Access-Control-Allow-Origin "*"

but it still presents me with the same error.

Any help would be appreciated.

Thank you.

Hey buddy, is there a workaround or a ETA to add this feature? :slight_smile: I haven’t heard any feedback since my last reply and I just wanna make sure I can achieve this or I should give up :stuck_out_tongue:

I personally had to stop using Virtualmin temporarily for unrelated reasons, but before I did I hadn’t managed to solve this.


Did you got this working in the end?


Unfortunately no =(

If you need to point sub-domain(e.g. to some other folder under parents public_html (e.g. wp-content) folder, but you got error while trying to change sub-domains “Website documents sub-directory” under Server Configuration / Website Options, then I got it working like this:

  1. enable sub-domain feature on Virtualmin Configuration,
  2. rename wp-content folder to something different in your public_html (e.g. old-content),
  3. create sub-domain named,
  4. copy-paste content from old-content to wp-content,
  5. if you want, you can change domain name to now (leave home directory unchanged) and you can now serve /wp-content under You should also request new ssl certificate after changing sub-domains name.
Sounds kind of silly to use this kind of workaround in such a great software as Virtualmin but anyways, this is how i got it working. Hope it works in your case as well.

DUDE! That’s awesome.

So the problem about Virtualmin is that it doesn’t allow you to create a subdomain to a pre-created folder of the same name.
I haven’t tested it yet but I will do asap. But one question: Does everything in Wordpress still work as expected? Can you Upload and install plugins from native UI (plugins > install new)?

And by the way, by following your tutorial, will I still be able to manage wp-content from the main domain or do I need to go to subdomains folder (under the main domain) as virtualmin is used to be?

Thank you very much buddy!


I’m facing 2 problems:

1- After creating the sub-domain and setting up the dns on CloudFlare, I’m still unable to visit the sub-domain. Virtualmin does not work well with special characters, so wp-content is not “allowed”. When I directly create it works great, even without setting up cloudflare.

2-Well… I’m trying to follow your tutorial but I’m unable to “Change domain name” to static for example.
After changing from to, my BIND DNS does not run anymore.


In my case, everything works as expected (don’t forget to follow points 3 and 4 of ), on my wordpress site source code i can see that everything previously inside gets served under

You don’t actually need to rename wp-content.domain, it does not have to be “static”, i think you can probably leave it wp-content (just change define function in wp-config and sql query accordingly). But i did not have any issues while renaming it. Hope removing this renamed sub-domain will get your DNS server working again.

Well, I had to go back and forth with backups and I don’t know why, but the last time I was able to create successfully.
But following keycdn tutorial was not enough. I had to install BETTER SEARCH AND REPLACE plugin and search for:

and replace for

Now my wp-content folder is being served by the subdomain. Awesome!
I will try to rename to static and see if it works. If it don’t, I don’t mind leaving it as wp-content.

Thank you very much buddy!


OK… One problem fixed, but another created.
In Wp-Admin some icons are missing. In Chrome Console I’m getting:

“Access to font at ‘’ from origin ‘’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”

I will try to figure it out. Did you have this type of problem too?