Point Domain To Sub-Directory In Apache Bitnami Virtual Hosts

In my previous post, I told you guys about installing multiple WordPress instances in a single VM. You can have your own reasons for doing that, but let's say you don’t want to create another VM in the cloud or configure a whole new server for your blog or website; and wanted to use existing server, VM, or OS so that's why you needed two WordPress instances. In this scenario, you’ll be needing multiple domains and your other WordPress instances will be installed in the sub directory.

In this case, your domain should be pointing at a sub directory, but DNS doesn’t work like that – either it’s CNAME or A record – you cannot point your domain to sub directory in DNS setting.


Here, DNS has failed to serve you, but Virtual Host will help you. Virtual host is a method in which you can host more than one website on a single machine.

In this tutorial, I’ll be using a real world example. My main website which resides at main public http folder is “www.forgeknives.com” and other website sitting in sub directory is “www.samknives.com” (main_website/samknives), public URL is “knives.southeastasia.cloudapp.azure.com” VM is installed in Microsoft Azure and I’m using Bitnami LAMP stack.

DNS Setting

Head to your domain provider, namecheap in my case, and point both domains to a Public URL or Public IP of your server, meaning, add CNAME or A Record respectively. In my case, I’m using Public URL which is “knives.southeastasia.cloudapp.azure.com”.



Don’t worry, let the server do the work.

Add Virtual Host Information in httpd.conf Files

If you have searched about adding vHosts you’ll come across the information where people have said to edit files like /etc/httpd/httpd.confor/etc/apache2/apache2.conf like the solution in this SuperUser thread. Well, they are right, but the problem is – it doesn’t work like this in Bitnami LAMP stack.

Connect to your VM because you're about to edit some files on the server.

If you are using Bitnami stack, your “httpd.conf” will be /opt/bitnami/apps/wordpress_instance/conf/httpd-vhosts.conf.

Edit files of both of your instances, i.e


Insert the following information in the files

  1. NameVirtualHost *: 80
  2. <VirtualHost *: 80>  
  3.    ServerName www.domain.tld  
  4.    ServerAlias domain.tld * .domain.tld  
  5.    DocumentRoot /www /public_http
  6. </VirtualHost>  
In my case, both of my files will be as follows.



ctrl+x > y > enter

Create Virtual Host

Follow these steps to create virtual hosts.
  1. Comment the line Include "/opt/bitnami/apps/wordpress/conf/httpd-prefix.conf" in the file


  2. Now, include the vHost configration files of both websites in.


  3. Update the URL.
  4. Restart Apache Server.
    $ sudo/opt/bitnami/ctlscript.sh restart apache

At this point, if you access your website using second domain, it’ll be pointing towards its sub directory


But, when you try to make use of .htaccess of WordPress, it won’t work; permalinks will be broken and you won't be able to access any post etc. You’ll probably get 404 or 500.


Two steps are needed to solve this problem, the first thing is, don’t forget to update URL, the second is Allowing Override.

Allow Overriding

When you search about the problem mentioned above, people on forums will be throwing all kinds of broken-.htaccess-file-maybe-solutions. But here, it’s not the solution. Don’t waste your time deleting and let WordPress create .htaccess file automatically. For security purposes, Bitnami has moved .htaccess file and merged with /opt/bitnami/apps/samknives/conf/httpd-app.conf.

This file, “AllowOverride” is set to “none”, go ahead and change it to “All”.


(We are talking about the instances which are only within sub directory).

Now, go ahead and test your website.


This is it. If you have any questions don’t forget to ask them below.

Up Next
    Ebook Download
    View all
    View all