awsgitea

Understand default .htaccess file configuration

One of our main goals is to configure Bitnami applications in the most secure way. For this reason, the configuration in the .htaccess files has been moved to the main application configuration files and set the AllowOverride option to None by default, if supported by the application.

NOTE: The Apache Software Foundation also recommends this configuration. To quote: “For security and performance reasons, do not set AllowOverride to anything other than None in your <Directory “/"> block. Instead, find (or create) the block that refers to the directory where you’re actually planning to place a .htaccess file.”

Understand .htaccess files

If the application supports using .htaccess files from custom locations, the contents of this file can be found in the /opt/bitnami/apache/conf/vhosts/htaccess/APPNAME-htaccess.conf file. For example:

  • The /opt/bitnami/apache/conf/vhosts/APPNAME-vhost.conf file is the main application configuration file. It also sources the APPNAME-htaccess.conf file.

      <VirtualHost 127.0.0.1:80 _default_:80>
        ServerAlias *
        DocumentRoot /opt/bitnami/APPNAME
        <Directory "/opt/bitnami/APPNAME">
          Options -Indexes +FollowSymLinks -MultiViews
          AllowOverride All
          Require all granted
        </Directory>
        Include "/opt/bitnami/apache/conf/vhosts/htaccess/APPNAME-htaccess.conf"
      </VirtualHost>
    
  • The /opt/bitnami/apache/conf/vhosts/htaccess/APPNAME-htaccess.conf file ships the content of all .htaccess files required by the application. It typically looks like this:

      <Directory "/opt/bitnami/APPNAME/cache">
        Deny from all
      </Directory>
      <Directory "/opt/bitnami/APPNAME/images">
        # Protect against bug 28235
        <IfModule rewrite_module>
          RewriteEngine On
          RewriteCond %{QUERY_STRING} \.[^\\/:*?\x22<>|%]+(#|\?|$) [nocase]
          RewriteRule . - [forbidden]
        </IfModule>
      </Directory>
      <Directory "/opt/bitnami/APPNAME/includes">
        Deny from all
      </Directory>
      <Directory "/opt/bitnami/APPNAME/languages">
        Deny from all
      </Directory>
      <Directory "/opt/bitnami/APPNAME/maintenance">
        Deny from all
      </Directory>
      <Directory "/opt/bitnami/APPNAME/maintenance/archives">
        Deny from all
      </Directory>
      <Directory "/opt/bitnami/APPNAME/serialized">
        Deny from all
      </Directory>
    

    If not, the .htaccess file can be found at /opt/bitnami/APPNAME/.htaccess.

  • Some applications do not have the /opt/bitnami/apache/conf/vhosts/htaccess/APPNAME-htaccess.conf file. For these cases, the file must be created manually.

Add a new section in the .htaccess file when installing a plugin

Some plugins, during their installation, create a .htaccess file in either the /opt/bitnami/APPNAME/ or in the /opt/bitnami/apps/APPNAME/plugins/ directory that cannot be read by Apache. For that reason, we recommend moving the content of that file to the /opt/bitnami/apache/conf/vhosts/htaccess/APPNAME-htaccess.conf file. Follow these steps:

  • Add a new entry in the /opt/bitnami/apache/conf/vhosts/htaccess/APPNAME-htaccess.conf file specifying the path where the htaccess file is (/opt/bitnami/APPNAME/ or /opt/bitnami/htdocs//plugins/) and pasting below the content of that file.

    NOTE: CONTENT is a placeholder, replace it with the content of the /opt/bitnami/APPNAME/.htaccess file created by the plugin.

      ...
      <Directory "/opt/bitnami/APPNAME">
      CONTENT
      </Directory>
    
  • Restart Apache to make the changes take effect:

      $ sudo /opt/bitnami/ctlscript.sh restart apache
    
Last modification February 9, 2023