googleredash

Access an application using only a single domain with Apache

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

The default Bitnami Apache server configuration allows you to access the server using the domain name or using the IP address directly.

Approach A: Bitnami installations using system packages

Redirect all domains to your own domain

To redirect all these domains to your own domain, follow the steps below:

  • Add the following configuration into the /opt/bitnami/apache2/conf/bitnami/bitnami.conf file. Remember to replace example.com with your own domain:

    <VirtualHost _default_:80>
      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^example.com$
      RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
      RewriteRule ^(.*)$ http://example.com$1 [R=permanent,L]
      ...
    
  • Add the following configuration into the /opt/bitnami/apache2/conf/bitnami/bitnami.conf file. Remember to replace example.com with your own domain:

    <VirtualHost _default_:443>
      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^example.com$
      RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
      RewriteRule ^(.*)$ https://example.com$1 [R=permanent,L]
      ...
    
  • Add the following configuration into any virtual host file located in the /opt/bitnami/apache2/conf/vhosts/ directory. Remember to replace example.com with your own domain:

    NOTE: Replace the PORT placeholder with the port number used by the virtual host.

    <VirtualHost _default_:443>
      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^example.com$
      RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
      RewriteRule ^(.*)$ https://example.com$1 [R=permanent,L]
      ...
    

Redirect all domains to your own domain and force HTTPS

To redirect all domains to your own domain and force HTTPS, follow the steps below:

  • Add the following configuration into the /opt/bitnami/apache2/conf/bitnami/bitnami.conf file. Remember to replace example.com with your own domain:

    <VirtualHost _default_:80>
      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
      RewriteRule ^(.*)$ https://example.com$1 [R=permanent,L]
      ...
    
  • Add the following configuration into the /opt/bitnami/apache2/conf/bitnami/bitnami-ssl.conf file. Remember to replace example.com with your own domain:

    <VirtualHost _default_:443>
      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^example.com$
      RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
      RewriteRule ^(.*)$ https://example.com$1 [R=permanent,L]
      ...
    
  • Add the following configuration into any virtual host file located in the /opt/bitnami/apache2/conf/vhosts/ directory. Remember to replace example.com with your own domain:

    NOTE: Replace the PORT placeholder with the port number used by the virtual host.

    <VirtualHost 127.0.0.1:PORT _default_:PORT>
      RewriteEngine On
      RewriteCond %{HTTP_HOST} !^example.com$
      RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
      RewriteRule ^(.*)$ https://example.com$1 [R=permanent,L]
      ...
    

Approach B: Self-contained Bitnami installations

Redirect all domains to your own domain

To redirect all these domains to your own domain, add the following configuration into the /opt/bitnami/apache2/conf/bitnami/bitnami.conf file. Remember to replace example.com with your own domain.

<VirtualHost _default_:80>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ http://example.com$1 [R=permanent,L]
...

<VirtualHost _default_:443>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ https://example.com$1 [R=permanent,L]
...

Redirect all domains to your own domain and force HTTPS

To redirect all domains to your own domain and force HTTPS, add the following configuration into the /opt/bitnami/apache2/conf/bitnami/bitnami.conf file. Remember to replace example.com with your own domain.

<VirtualHost _default_:80>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ https://example.com$1 [R=permanent,L]
...

<VirtualHost _default_:443>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
RewriteRule ^(.*)$ https://example.com$1 [R=permanent,L]
...

Watch the following tutorial about how to force HTTPS:

Last modification June 9, 2020